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

Re: Makeing history harmless



Phil Pennock sent me the following 0.9K:

> On 2006-10-12 at 04:47 +0200, Meino Christian Cramer wrote:
> >  Is it possible to write a "something" to filter out certain commands 
> >  or to modify certain commands before they were copied from the
> >  commandline into the history ?
> 
> (1) setopt hist_ignore_space
>     Then get used to typing a space at the start of the line of
>     dangerous commands.  The item remains in the history only until the
>     next command is run.

It took me a bit to catch on to the fact that the most recently executed
line is always in the history.

> (2) Combine that option with a new accept-line to apply it automatically
> 
> -----------------------------< cut here >-------------------------------
> setopt hist_ignore_space
> 
> function histfilter-accept-line {
>   emulate -L zsh
>   case ${${(z)BUFFER}[1]} in
>   (rm|rmdir) BUFFER=" $BUFFER" ;;
>   esac
>   zle .accept-line
> }
> 
> zle -N histfilter-accept-line
> zle -A histfilter-accept-line accept-line
> -----------------------------< cut here >-------------------------------

I do this with:

   setopt hist_ignore_space
   alias rm=' rm'

Is there an advantage to using the widget?

-- 
Chris Johnson
cjohnson@xxxxxxxxxx
http://www.cs.utk.edu/~cjohnson



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