Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: vared history not working inside scripts



On Jan 13,  7:55pm, rahul wrote:
} 
} On the command line, "vared -h" allows me to access history using arrow
} keys or Control-R.
} Inside a script, nothing happens. Is there some setting I have to make in
} scripts.

History is normally disabled in scripts.  On the "Expansion" summary page
in the documentation, under "History Expansion", it is noted that "This
is performed only in interactive shells."

To enable history in a script, you need to run the "fc -p" command to
initialize it.  If your script is going to be run as a shell function,
it's best to use "fc -a -p" to automatically restore the regular shell
history when the function exits.

fc -p [ -a ] [ FILENAME [ HISTSIZE [ SAVEHISTSIZE ] ] ]

     `fc -p' pushes the current history list onto a stack and switches
     to a new history list.  If the -a option is also specified, this
     history list will be automatically popped when the current
     function scope is exited, which is a much better solution than
     creating a trap function to call `fc -P' manually.  If no
     arguments are specified, the history list is left empty, $HISTFILE
     is unset, and $HISTSIZE & $SAVEHIST are set to their default
     values.  If one argument is given, $HISTFILE is set to that
     filename, $HISTSIZE & $SAVEHIST are left unchanged, and the history
     file is read in (if it exists) to initialize the new list.  If a
     second argument is specified, $HISTSIZE & $SAVEHIST are instead
     set to the single specified numeric value.  Finally, if a third
     argument is specified, $SAVEHIST is set to a separate value from
     $HISTSIZE.  You are free to change these environment values for
     the new history list however you desire in order to manipulate the
     new history list.

     `fc -P' pops the history list back to an older list saved by `fc
     -p'.  ...

There's an example of this in Functions/Misc/sticky-note in the sources
(usually found at ${^fpath}/sticky-note(N:[1]) after installation).



Messages sorted by: Reverse Date, Date, Thread, Author