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

Re: do not write certain commands to history file



On 25 August 2010 22:55, Benjamin R. Haskell <zsh@xxxxxxxxxx> wrote:
> On Wed, 25 Aug 2010, Eric Smith wrote:
>
>> 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*)
>>     ]]
>> }
>
> Where are you setting $arg?  Do you mean $line? or are you trying to
> match *foobar* in $argv?
>
> If the latter, you can't just match an array against a pattern (since
> there's no sensible default for whether it's conjunctive or disjunctive
> [any or all]).  I'm not sure of the [[ ]] form offhand, but the (( ))
> form would be:
>
> [[ # what you already have ]] && (( ! $argv[(I)*foobar*] ))

What are you talking about? There's no $arg anywhere, and no arrays.
zshaddhistory() is passed the entire command line in a single
argument.

-- 
Mikael Magnusson



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