zsh-users
 help / color / mirror / code / Atom feed
* Makeing history harmless
@ 2006-10-12  2:47 Meino Christian Cramer
  2006-10-12  5:09 ` Phil Pennock
  0 siblings, 1 reply; 4+ messages in thread
From: Meino Christian Cramer @ 2006-10-12  2:47 UTC (permalink / raw)
  To: zsh-users

Hi,

 there are several kind of commands -- mainly things like "rm" --
 which may be harmless only in a certain context.

 The history function of zsh remembers the command but not the
 contents.

 Therefore one may look up (for example via ^R) the history and gives
 a "go" to a command, which he _really_ does not want by accident.

 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 ?

 Kind regards and keep hacking!
 mcc


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Makeing history harmless
  2006-10-12  2:47 Makeing history harmless Meino Christian Cramer
@ 2006-10-12  5:09 ` Phil Pennock
  2006-10-12 13:15   ` Chris Johnson
  0 siblings, 1 reply; 4+ messages in thread
From: Phil Pennock @ 2006-10-12  5:09 UTC (permalink / raw)
  To: Meino Christian Cramer; +Cc: zsh-users

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.

(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 >-------------------------------

Regards,
-Phil


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Makeing history harmless
  2006-10-12  5:09 ` Phil Pennock
@ 2006-10-12 13:15   ` Chris Johnson
  2006-10-13  9:16     ` Phil Pennock
  0 siblings, 1 reply; 4+ messages in thread
From: Chris Johnson @ 2006-10-12 13:15 UTC (permalink / raw)
  To: zsh-users

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@cs.utk.edu
http://www.cs.utk.edu/~cjohnson


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Makeing history harmless
  2006-10-12 13:15   ` Chris Johnson
@ 2006-10-13  9:16     ` Phil Pennock
  0 siblings, 0 replies; 4+ messages in thread
From: Phil Pennock @ 2006-10-13  9:16 UTC (permalink / raw)
  To: zsh-users

On 2006-10-12 at 09:15 -0400, Chris Johnson wrote:
> 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 ?

> I do this with:

I do neither, I was just helping the OP, Meino.  :^)

>    setopt hist_ignore_space
>    alias rm=' rm'
> 
> Is there an advantage to using the widget?

Not really, unless you want to avoid global aliases whilst writing
something which can special-case things like "svn rm"; you could have
nested case statements examining different items in ${(z)BUFFER} and
possibly triggering other effects too.  Heck, build a whole new dispatch
system for command hooks, a la compsys.  ;^)

In summary, zsh is mighty and there's more than one way to do it.

-Phil


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-10-13  9:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-10-12  2:47 Makeing history harmless Meino Christian Cramer
2006-10-12  5:09 ` Phil Pennock
2006-10-12 13:15   ` Chris Johnson
2006-10-13  9:16     ` Phil Pennock

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).