rlwrap

rlwrap is a wrapper for GNU readline. It can be used with an interactive Tcl to provide readline editing and command history functionality.

To use it with tclsh, start tclsh with:

rlwrap tclsh

Useful options are -c (file name completion) and -f (add words from a file to the completion list).

To use rlwrap with tclsh with file name completion type:

rlwrap -c tclsh

It would be nice to have a file of all words used in Tcl: commands and subcommands to set rlwrap up using the -f option.

info commands and info procs could help with that. Maybe there are some *.syn files out there to provide such a database.

Alternatives

Current

enhance

The rlwrap alternative bundled with the Tecla command-line editing library , which offers tcsh-like interactive command line editing. Has both vi and emacs key bindings. The former are allegedly better than rlwrap's.

rlfe

Available from http://per.bothner.com/software/#rlfe and as a Debian/Ubuntu package.

socat readline

PT: It is also possible to use socat to wrap readline around your tclsh executable.

# Rename your tclsh8.6 binary to tclsh8.6.exe then create the following wrapper script
mv tclsh8.6 tclsh8.6.exe
cat > tclsh8.6 <<EOF
#!/bin/bash
bin=$(readlink -f $0).exe
if [ $# -lt 1 ]; then
    exec socat READLINE,history=$HOME/.tclsh_history EXEC:$bin,pty,ctty,echo=0
else
    exec $bin $*
fi

The same can be usefully done for wish.

Outdated

Cle

Cle (http://kaolin.unice.fr/Cle/ ) is another command history filter. Unmaintained since 1999.

fep

fep was once a common alternative to rlwrap, though it hasn't been updated since 1995. The canonical URL for its source code is ftp://ftp.sra.co.jp/pub/cmd/fep/fep.tar.gz . The pkgsrc package with the included patches is useful if you want to build it on a modern system.

Discussion

RS 2013-11-01: For more convenience, you can put

 alias tclsh='rlwrap -c tclsh8.5'

in your .bashrc or a similar startup file. On Ubuntu, rlwrap can be fetched with apt-get install.


fr 2016-12-20: For vi editor mode add 2 lines to ~.inputrc or /etc/inputrc

set editor-mode vi
set keymap vi