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
13 # Read a complete line (script)
14 set prompt
"${prefix}jim> "
17 if {[history getline
$prompt line
] < 0} {
24 if {[info complete
$cmd char
]} {
35 # Don't bother adding single char commands to the history
36 if {[string length
$cmd] > 1} {
38 history save
$histfile
41 # Evaluate the script and display the error
43 set result
[eval $cmd]
45 } on
{error return break continue signal
} {result opts
} {
46 set rcname
[info returncodes
$opts(-code)]
47 if {$rcname eq
"ok" } {
48 # Note: return set -code to 0
50 } elseif
{$rcname eq
"error"} {
51 set result
[errorInfo
$result]
53 set prefix
"\[$rcname\] "