zsh-users
 help / color / mirror / code / Atom feed
* do not write certain commands to history file
@ 2010-08-25 19:26 Eric Smith
  2010-08-25 19:46 ` Mikael Magnusson
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Eric Smith @ 2010-08-25 19:26 UTC (permalink / raw)
  To: zsh-users

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).

-- 
- Eric Smith


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

* Re: do not write certain commands to history file
  2010-08-25 19:26 do not write certain commands to history file Eric Smith
@ 2010-08-25 19:46 ` Mikael Magnusson
  2010-08-25 20:36   ` Eric Smith
  2010-08-26  8:10 ` do not write certain commands to history file Sebastian Stark
  2010-08-26  8:28 ` Sebastian Stark
  2 siblings, 1 reply; 10+ messages in thread
From: Mikael Magnusson @ 2010-08-25 19:46 UTC (permalink / raw)
  To: zsh-users

On 25 August 2010 21:26, Eric Smith <es@fruitcom.com> 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/*" ]]
}

I tried using fc -p, print -s, but no way i could think of stopped
writing things to the history file while also keeping it in the local
history buffer.

-- 
Mikael Magnusson


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

* Re: do not write certain commands to history file
  2010-08-25 19:46 ` Mikael Magnusson
@ 2010-08-25 20:36   ` Eric Smith
  2010-08-25 20:41     ` Mikael Magnusson
  2010-08-25 20:55     ` Benjamin R. Haskell
  0 siblings, 2 replies; 10+ messages in thread
From: Eric Smith @ 2010-08-25 20:36 UTC (permalink / raw)
  To: zsh-users


-- 
- Eric Smith
Mikael Magnusson said:
> On 25 August 2010 21:26, Eric Smith <es@fruitcom.com> 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*)
    ]]
}


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

* Re: do not write certain commands to history file
  2010-08-25 20:36   ` Eric Smith
@ 2010-08-25 20:41     ` Mikael Magnusson
  2010-08-25 20:55     ` Benjamin R. Haskell
  1 sibling, 0 replies; 10+ messages in thread
From: Mikael Magnusson @ 2010-08-25 20:41 UTC (permalink / raw)
  To: zsh-users

On 25 August 2010 22:36, Eric Smith <es@fruitcom.com> wrote:
>
> --
> - Eric Smith
> Mikael Magnusson said:
>> On 25 August 2010 21:26, Eric Smith <es@fruitcom.com> 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*)
>    ]]
> }

Just doing zshaddhistory() { [[ $1 != *foobar* ]] } should be enough.
(and works for me).

-- 
Mikael Magnusson


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

* Re: do not write certain commands to history file
  2010-08-25 20:36   ` Eric Smith
  2010-08-25 20:41     ` Mikael Magnusson
@ 2010-08-25 20:55     ` Benjamin R. Haskell
  2010-08-25 21:01       ` Mikael Magnusson
  2010-08-25 21:01       ` do not write certain commands to history file - solved Eric Smith
  1 sibling, 2 replies; 10+ messages in thread
From: Benjamin R. Haskell @ 2010-08-25 20:55 UTC (permalink / raw)
  To: zsh-users

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*] ))

-- 
Best,
Ben


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

* Re: do not write certain commands to history file
  2010-08-25 20:55     ` Benjamin R. Haskell
@ 2010-08-25 21:01       ` Mikael Magnusson
  2010-08-25 21:11         ` Benjamin R. Haskell
  2010-08-25 21:01       ` do not write certain commands to history file - solved Eric Smith
  1 sibling, 1 reply; 10+ messages in thread
From: Mikael Magnusson @ 2010-08-25 21:01 UTC (permalink / raw)
  To: Benjamin R. Haskell; +Cc: zsh-users

On 25 August 2010 22:55, Benjamin R. Haskell <zsh@benizi.com> 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


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

* Re: do not write certain commands to history file - solved
  2010-08-25 20:55     ` Benjamin R. Haskell
  2010-08-25 21:01       ` Mikael Magnusson
@ 2010-08-25 21:01       ` Eric Smith
  1 sibling, 0 replies; 10+ messages in thread
From: Eric Smith @ 2010-08-25 21:01 UTC (permalink / raw)
  To: zsh-users


> 
> [[ # what you already have ]] && (( ! $argv[(I)*foobar*] ))

This cooks, thanks Ben,
Some new words for me as well :)


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

* Re: do not write certain commands to history file
  2010-08-25 21:01       ` Mikael Magnusson
@ 2010-08-25 21:11         ` Benjamin R. Haskell
  0 siblings, 0 replies; 10+ messages in thread
From: Benjamin R. Haskell @ 2010-08-25 21:11 UTC (permalink / raw)
  To: Mikael Magnusson; +Cc: zsh-users

On Wed, 25 Aug 2010, Mikael Magnusson wrote:

> On 25 August 2010 22:55, Benjamin R. Haskell wrote:
> > On Wed, 25 Aug 2010, Eric Smith wrote:
> >
> >> [...]
> >>
> >> zshaddhistory() {
> >>     [...trimmed...]
> >>
> >>     [[          [...trimmed...]
> >>         && ${arg} != (*foobar*)
> >>     ]]
> >> }
> >
> > Where are you setting $arg?  Do you mean $line? or are you trying to
> > match *foobar* in $argv?
> 
> What are you talking about?

See the portion of his original function I left above.


> There's no $arg anywhere, and no arrays.  zshaddhistory() is passed 
> the entire command line in a single argument.

Which is accessible via ${argv}, I suppose.  But, yeah, overkill.  I was 
thinking of finding *foobar* in a general function's $argv.

-- 
Best,
Ben


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

* Re: do not write certain commands to history file
  2010-08-25 19:26 do not write certain commands to history file Eric Smith
  2010-08-25 19:46 ` Mikael Magnusson
@ 2010-08-26  8:10 ` Sebastian Stark
  2010-08-26  8:28 ` Sebastian Stark
  2 siblings, 0 replies; 10+ messages in thread
From: Sebastian Stark @ 2010-08-26  8:10 UTC (permalink / raw)
  To: Eric Smith; +Cc: zsh-users


Am 25.08.2010 um 21:26 schrieb Eric Smith:

> 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)?

What I do is two things: For commands that I never want to see in my history I make an alias for it that begins with a space character, like so:

  alias mkpwlink=' mkpwlink'

If the shell option histignorespace is set, the mkpwlink command will not appear in the history.

If I want to run a whole "session" of commands without history, I use the history stack:

  HISTSTACK=0
  alias histpush="fc -p && ((HISTSTACK += 1))"
  alias histpop="fc -P && ((HISTSTACK -= 1))"

I use the $HISTSTACK variable in my prompt to keep track of my history level.


Sebastian

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

* Re: do not write certain commands to history file
  2010-08-25 19:26 do not write certain commands to history file Eric Smith
  2010-08-25 19:46 ` Mikael Magnusson
  2010-08-26  8:10 ` do not write certain commands to history file Sebastian Stark
@ 2010-08-26  8:28 ` Sebastian Stark
  2 siblings, 0 replies; 10+ messages in thread
From: Sebastian Stark @ 2010-08-26  8:28 UTC (permalink / raw)
  To: Eric Smith; +Cc: zsh-users


Am 25.08.2010 um 21:26 schrieb Eric Smith:

> 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)?

What I do is two things: For commands that I never want to see in my history I make an alias for it that begins with a space character, like so:

 alias mkpwlink=' mkpwlink'

If the shell option histignorespace is set, the mkpwlink command will not appear in the history.

If I want to run a whole "session" of commands without history, I use the history stack:

 HISTSTACK=0
 alias histpush="fc -p && ((HISTSTACK += 1))"
 alias histpop="fc -P && ((HISTSTACK -= 1))"

I use the $HISTSTACK variable in my prompt to keep track of my history level.


Sebastian

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

end of thread, other threads:[~2010-08-26  8:30 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-25 19:26 do not write certain commands to history file Eric Smith
2010-08-25 19:46 ` Mikael Magnusson
2010-08-25 20:36   ` Eric Smith
2010-08-25 20:41     ` Mikael Magnusson
2010-08-25 20:55     ` Benjamin R. Haskell
2010-08-25 21:01       ` Mikael Magnusson
2010-08-25 21:11         ` Benjamin R. Haskell
2010-08-25 21:01       ` do not write certain commands to history file - solved Eric Smith
2010-08-26  8:10 ` do not write certain commands to history file Sebastian Stark
2010-08-26  8:28 ` Sebastian Stark

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).