Updated 2016-03-06 18:04:19 by EMJ

history, a built-in command, manipulates the history list.

Synopsis  edit

history ?option? ?arg arg ...?

Supported subcommands are:
[history add] script ?exec?
[history change] newValue ?event?
[history clear]
[history event] ?event?
[history info] ?count?
[history keep] ?count?
[history nextid]
[history redo] ?event?

Description  edit

history, with no additional arguments, is equivalent to [history info].

Usage  edit

You could, of course, just use it as is, but at least parts of it are "intended for use in commands that implement new forms of history substitution" (as stated in the official documentation). There actually are such commands, implemented by the standard unknown (they are rather csh-like).
        if {$name eq "!!"} {
            set newcmd [history event]
        } elseif {[regexp {^!(.+)$} $name -> event]} {
            set newcmd [history event $event]
        } elseif {[regexp {^\^([^^]*)\^([^^]*)\^?$} $name -> old new]} {
            set newcmd [history event -1]
            catch {regsub -all -- $old $newcmd $new newcmd}
        if {[info exists newcmd]} {
            tclLog $newcmd
            history change $newcmd 0
            uplevel 1 [list ::catch $newcmd  ::tcl::UnknownResult ::tcl::UnknownOptions]
            dict incr ::tcl::UnknownOptions -level
            return -options $::tcl::UnknownOptions $::tcl::UnknownResult