1 # Simple example of how the history extension
2 # can be used to provide line editing and history
4 # Build jimsh with the history extension and enable line editing (the default)
5 # ./configure --with-ext=history
7 package require
history
9 set histfile
[env HOME
]/.jtclsh
10 history load $histfile
11 # Use the standard Tcl autocompletion
12 history completion tcl
::autocomplete
15 # Read a complete line (script)
16 set prompt
"${prefix}jim> "
19 if {[history getline
$prompt line
] < 0} {
26 if {[info complete
$cmd char
]} {
37 # Don't bother adding single char commands to the history
38 if {[string length
$cmd] > 1} {
40 history save
$histfile
43 # Evaluate the script and display the error
45 set result
[eval $cmd]
47 } on
{error return break continue signal
} {result opts
} {
48 set rcname
[info returncodes
$opts(-code)]
49 if {$rcname eq
"ok" } {
50 # Note: return set -code to 0
52 } elseif
{$rcname eq
"error"} {
53 set result
[errorInfo
$result]
55 set prefix
"\[$rcname\] "