moros icon indicating copy to clipboard operation
moros copied to clipboard

Add better shell scripting capabilities

Open vinc opened this issue 10 months ago • 0 comments

At the moment we can only run one command at a time in the REPL and in any shell script, which is pretty limiting. This PR will evolve the shell into a proper scripting language inspired by Ruby allowing us to do much more with it:

  • [ ] Add ; to separate commands
  • [ ] Add and operator
  • [ ] Add or operator
  • [ ] Add not operator
  • [ ] Add test program
  • [ ] Add def <name> <args>* [do] <commands> end (function definition)
  • [ ] Add if <condition> [do] <commands> [else <commands>] end (conditional)
  • [ ] Add for <var> in <list> [do] <commands> end (loop)
  • [ ] Add $(<command>) (command substitution)
  • [ ] Add <command> --> <command> (pipe)

Example:

def hello name
  print "Hello, $name!"
end

if test -e $USER
  hello World
else
  hello $USER
end

for file in $(list /tmp/*.tmp)
  drop $file
end

A real shell script could be a redefinition of move as copy + drop instead of being a dedicated Rust program:

#! shell

def usage
    print "Usage: move <src> <dst>"
end

for arg in $*
    if test -e $arg "-h" or test -e $arg "--help"
        usage
        exit 0
    end
end

set src $1
set dst $2

if test -e $src "" or test -e $dst ""
    usage
    exit 1
end
        
copy $src $dst and drop $src

vinc avatar Jun 26 '25 07:06 vinc