Updated 2013-01-18 20:56:15 by pooryorick

Usually short for "an interp alias" (especially when source and target are in the same interpreter, and the interp part would be confusing), but can be used as a generic term for commands of similar nature.

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 require

or 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: