Make sure exec.test cleans up better
[jimtcl.git] / examples / jtclsh.tcl
blobdc92bcaeb7535776e73f579b92fe248904476175
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 while 1 {
12 if {[history getline "jim> " cmd] < 0} {
13 break
15 if {$cmd eq "h"} {
16 history show
17 continue
19 # Don't bother adding single char commands to the history
20 if {[string length $cmd] > 1} {
21 history add $cmd
22 history save $histfile
24 # jimsh also does:
25 # - check for a complete command: [info complete]
26 # - handle other non-error return codes and changes the prompt: [info returncodes]
27 # - displays the complete error message: [errorInfo]
28 try {
29 set result [eval $cmd]
30 if {$result ne {}} {
31 puts $result
33 } on error msg {
34 puts $msg