wduquette / molt

Embeddable TCL Interpreter for Rust applications
BSD 3-Clause "New" or "Revised" License
103 stars 12 forks source link

Implement "-e CMD" in moltsh #70

Open dbohdan opened 4 years ago

dbohdan commented 4 years ago

Jim Tcl has the command line option -e CMD that prints the result of the last command in the script CMD.

> jimsh -e 'set a $argv; lappend a baz' foo bar
foo bar baz

It makes Jim easier to use from the shell than Tcl 8.x, particularly in pipelines where you can't do echo $code | tclsh. It would be nice to see this option in the Molt shell. In general, I think Jim Tcl is worth looking at as a source of ideas for any new Tcl implementation.

wduquette commented 4 years ago

Got an opinion about .tclshrc (or, more likely, .moltrc, or whatever the molt-shell client picks)? I never much used it with tclsh myself, so I haven't implemented it.

dbohdan commented 4 years ago

For what it's worth, I use .tclshrc. I import Tcllib packages that are often needed in interactive use like fileutil, define procs like bexec, and most importantly start the tclreadline REPL. It is less important in a Tcl implementation that has a built-in Readline clone, like Jim Tcl, but I still use .jimrc to source my jimlib.

My primary suggestion about .moltrc is to acknowledge the XDG directories and store .moltrc in $env(XDG_CONFIG_HOME) (which is ~/.config/ by default) or its subdirectory and the command history in $env(XDG_DATA_HOME) (~/.local/share/ by default) or a subdirectory rather than pollute the user's home directory with another config and history file. Modern shells like fish follow this convention.

wduquette commented 4 years ago

Added #89 to cover ~/.config/molt/config.tcl.