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

Re: Hiding command from history



On Tue, 3 Feb 2015 14:34:49 +0200
İsmail Dönmez <ismail@xxxxxxxxx> wrote:
> On Tue, Feb 3, 2015 at 2:13 PM, Peter Stephenson
> <p.stephenson@xxxxxxxxxxx> wrote:
> > On Tue, 3 Feb 2015 13:29:34 +0200
> > İsmail Dönmez <ismail@xxxxxxxxx> wrote:
> >> I know I can set HIST_IGNORE_SPACE and any command starting with space
> >> will not be logged in history. But with that I have many aliases like
> >>
> >> alias ls=" ls"
> >> alias mv=" mv"
> >>
> >> etc. So, I wonder if there is an easier way to blacklist multiple
> >> commands from history without creating an alias for each of them?
> >
> > Have a look at HISTORY_IGNORE in the zshparam manule
> 
> This seems to be the best option but I can't figure out the syntaxt.
> Bash's similar HISTIGNORE syntax
> 
> HISTORY_IGNORE="rm *:ls *"
> 
> doesn't seem to work. Tried with
> 
> > HISTORY_IGNORE="rm *:ls *" zsh

HISTORY_IGNORE just stops things being written to history files;
I don't think that's quite you want.  If it was, it's a single pattern,
so you should be able to do

HISTORY_IGNORE="(rm|ls) *"

You can do this, though:

zshaddhistory() { [[ $1 = (ls|rm)\ * ]] && return 1; }

and indeed there's no reason I can think of why you couldn't simply
define

zshaddhistory() { [[ $1 = ${~HISTORY_IGNORE} ]] && return 1; }

pws



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