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

Re: permanent commands in history?

On Dec 17,  9:49pm, Dominik Vogt wrote:
} Subject: permanent commands in history?
} There are some command lines that I use frequently [...]
} Most of the time these are in my command line history and
} accessing them is easy [...]
} However, once in a while these are removed from the history file
} (1000 lines).  Is is possible to make certain command lines
} permanent in the history file so that I never have to retype them?

Not exactly, but you can make it appear that way.

Put the commands in a file somewhere, say, ~/.zhistalways or whatever.
Then in ~/.zshrc, use the command

	fc -R ~/.zhistalways

This assumes that ((HISTSIZE > SAVEHIST)), because otherwise the history
read from $HISTFILE will cause those commands to fall off again.

Or you could use

	< ~/.zhistalways >> $HISTFILE

instead, to assure that those commands are always the most recent ones.

Either way, I'd recommend setting either the HIST_EXPIRE_DUPS_FIRST or the
HIST_IGNORE_ALL_DUPS options (assuming you're using 3.1.9).

Or you can take a different approach, and avoid using the history at all,
and instead use the completion system (again assuming 3.1.9).  I have a
file named "_cmdselect" in my $fpath:

    #compdef -k menu-select ^X:
    local -a commands
    commands=(${(f)"$(cat)"}) <<\EOF
     (list of commonly-repeated commands goes here, one per line)
    compadd -Q "$commands[@]"

When I run "compinit", it finds that file, autoloads it, and binds it to
the key sequence control-X colon.  When I want to use one of my frequent
commands, I type a prefix and then C-x : and the completion system does
the rest; if I didn't make the prefix unique, I get a menu from which to
choose.  (If you don't like the menuing behavior, change `menu-select' to
`complete-word' or `menu-complete' in the above.)

Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   

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