Skip to content

Add better shell scripting capabilities#752

Draft
vinc wants to merge 2 commits into
trunkfrom
feature/shell-v2
Draft

Add better shell scripting capabilities#752
vinc wants to merge 2 commits into
trunkfrom
feature/shell-v2

Conversation

@vinc
Copy link
Copy Markdown
Owner

@vinc vinc commented Jun 26, 2025

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 vinc mentioned this pull request Jun 29, 2025
5 tasks
@vinc vinc added enhancement New feature or request experiment Experiment that might never be merged labels Jul 6, 2025
@vinc
Copy link
Copy Markdown
Owner Author

vinc commented Apr 17, 2026

Command substitution has been implemented in #822

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request experiment Experiment that might never be merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant