MGS [2004/04/11] - A quick proc to set/query interp aliases:
proc alias {args} { set argc [llength $args] set interp {} switch -- $argc { 0 { foreach alias [lsort [interp aliases]] { puts "\[$alias\] -> \[[interp alias $interp $alias]\]" } } 1 { set alias [lindex $args 0] puts "\[$alias\] -> \[[interp alias $interp $alias]\]" } default { set alias [lindex $args 0] set cmd [lrange $args 1 end] eval [linsert $cmd 0 interp alias $interp $alias $interp] } } }Then in my ~/.tclshrc file I put:
if { $tcl_interactive } { set file [file join $::env(HOME) .tclsh aliases] if { ![catch {open $file r} f] } { while { [gets $f line] > -1 } { if { [string match #* [string trim $line]] } { continue } set alias [lindex $line 0] set cmd [lrange $line 1 end] puts "alias \[$alias\] -> \[$cmd\]" eval [linsert $cmd 0 interp alias {} $alias {}] } close $f } }And then I create the file ~/.tclsh/aliases containing the lines:
q exit pf package forget pr package requireor whatever. Then you can do:
> alias [pf] -> [package forget] [pr] -> [package require] [q] -> [exit] > alias q [q] -> [exit] > alias quit exit 0 quit
See also:
- interp alias
- interp aliases
- Introspection shortcomings, subsection Introspection on aliases.