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

Re: do not write certain commands to history file



-- 
- Eric Smith
Mikael Magnusson said:
> On 25 August 2010 21:26, Eric Smith <es@xxxxxxxxxxxx> wrote:
> > Oh zsh seers,
> >
> > What is the way to match certain words in commands so that they
> > are not written to the history file (but might possibly remain in the
> > buffer history which does not worry me much)?
> >
> > (I saw a thread on history encryption, seems a bit heavy handed).
> 
> Remaining in the history buffer and writing to the history file seems
> to be linked together. You can however use the zshaddhistory()
> function to exclude things based on shellcode.
> 
> zshaddhistory() {
>   [[ $1 != "display ~/pron/*" ]]
> }
> 

Thanks Mikael. If it is not in the buffer I do not care.
But I cannot work your example.

Found this below in a config file somewhere and thought I could
adapt it.  I want to exclude all commands that have "foobar"
anywhere in them, as the command or in the arg list.
Quick hack did not work.  All lines are still written to
the history file.

zshaddhistory() {
    local line=${1%%$'\n'}
    local cmd=${line%% *}

    [[ ${#line} -ge 5
        && ${cmd} != "rm"
        && ${cmd} != (l|l[sal])
        && ${cmd} != (c|cd)
        && ${cmd} != (m|man)
        && ${arg} != (*foobar*)
    ]]
}



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