Keeping clear out of history

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Keeping clear out of history

Ken MacKenzie
OK, so confession 1, I am a long time bash user
confession 2 all of my ksh experience is on solaris

However in a when in Rome moment I am realizing how much I like ksh in openbsd,
but one minor thing. I don't like how much clear ends up in my history file. So
I am wondering what I can do to suppress a command going to history.


Lets put my .profile here for reference

# $OpenBSD: dot.profile,v 1.5 2018/02/02 02:29:54 yasuoka Exp $
#
# sh/ksh initialization

. /etc/ksh.kshrc

PATH=$HOME/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin:/usr/games:$HOME/.local/bin
PS1="[\u@\h: \W]$ "
HISTFILE=$HOME/.ksh_history
HISTSIZE=1000
export PATH HOME TERM PS1 HISTFILE HISTSIZE

# For now clearing out clear from history when starting
sed -i '/^clear$/d' $HISTFILE

bind -m '^L'=clear'^J'
# I wish this worked
# bind -m '^L'=clear'^J';sed -i '$d' $HISTFILE

alias ll='ls -l'
alias la='ls -la'
alias watch='gnuwatch'


As you can see I tried adding the ; sed after my bind, I also tried it with &&
sed and that did not work. Both of course remove the sed from history and not
the clear. I guess I could remove the 2nd to last line. But before I go that sed
route is there a cleaner way to prevent a command from going to the HISTFILE?

Ken

Reply | Threaded
Open this post in threaded view
|

Re: Keeping clear out of history

Philippe Meunier
Ken M wrote:
># I wish this worked
># bind -m '^L'=clear'^J';sed -i '$d' $HISTFILE

You need to make sure that the sed command is inside the argument of bind.
Something like this:

bind -m '^L=^Uclear;sed -i \$d "$HISTFILE"^J^Y'

The ^Y is just there to paste back the current line content when you press
^L in the middle of an existing line; the double quotes are there in case
$HISTFILE contains a space.

Note that, even if you change $HISTFILE, the clear command will still
appear in ksh's history when you press the up arrow, so I'm not sure what
you are trying to do is worth the trouble.

Cheers,

Philippe


Reply | Threaded
Open this post in threaded view
|

Re: Keeping clear out of history

Anton Lindqvist-2
In reply to this post by Ken MacKenzie
On Mon, Jul 30, 2018 at 08:11:44PM -0400, Ken M wrote:

> OK, so confession 1, I am a long time bash user
> confession 2 all of my ksh experience is on solaris
>
> However in a when in Rome moment I am realizing how much I like ksh in openbsd,
> but one minor thing. I don't like how much clear ends up in my history file. So
> I am wondering what I can do to suppress a command going to history.
>
>
> Lets put my .profile here for reference
>
> # $OpenBSD: dot.profile,v 1.5 2018/02/02 02:29:54 yasuoka Exp $
> #
> # sh/ksh initialization
>
> . /etc/ksh.kshrc
>
> PATH=$HOME/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin:/usr/games:$HOME/.local/bin
> PS1="[\u@\h: \W]$ "
> HISTFILE=$HOME/.ksh_history
> HISTSIZE=1000
> export PATH HOME TERM PS1 HISTFILE HISTSIZE
>
> # For now clearing out clear from history when starting
> sed -i '/^clear$/d' $HISTFILE
>
> bind -m '^L'=clear'^J'
> # I wish this worked
> # bind -m '^L'=clear'^J';sed -i '$d' $HISTFILE
>
> alias ll='ls -l'
> alias la='ls -la'
> alias watch='gnuwatch'
>
>
> As you can see I tried adding the ; sed after my bind, I also tried it with &&
> sed and that did not work. Both of course remove the sed from history and not
> the clear. I guess I could remove the 2nd to last line. But before I go that sed
> route is there a cleaner way to prevent a command from going to the HISTFILE?

Check out HISTCONTROL[1] and ignorespace in particular. Adding something
along the lines to your ~/.kshrc should do the trick:

  HISTCONTROL=ignorespace
  bind -m '^L'='^U clear^J^Y' # note the intentional space before clear

[1] https://man.openbsd.org/ksh#HISTCONTROL

Reply | Threaded
Open this post in threaded view
|

Re: Keeping clear out of history

Solene Rapenne
In reply to this post by Ken MacKenzie
Ken M <[hidden email]> wrote:

> OK, so confession 1, I am a long time bash user
> confession 2 all of my ksh experience is on solaris
>
> However in a when in Rome moment I am realizing how much I like ksh in openbsd,
> but one minor thing. I don't like how much clear ends up in my history file. So
> I am wondering what I can do to suppress a command going to history.
>
>
> Lets put my .profile here for reference
>
> # $OpenBSD: dot.profile,v 1.5 2018/02/02 02:29:54 yasuoka Exp $
> #
> # sh/ksh initialization
>
> . /etc/ksh.kshrc
>
> PATH=$HOME/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin:/usr/games:$HOME/.local/bin
> PS1="[\u@\h: \W]$ "
> HISTFILE=$HOME/.ksh_history
> HISTSIZE=1000
> export PATH HOME TERM PS1 HISTFILE HISTSIZE
>
> # For now clearing out clear from history when starting
> sed -i '/^clear$/d' $HISTFILE
>
> bind -m '^L'=clear'^J'
> # I wish this worked
> # bind -m '^L'=clear'^J';sed -i '$d' $HISTFILE
>
> alias ll='ls -l'
> alias la='ls -la'
> alias watch='gnuwatch'
>
>
> As you can see I tried adding the ; sed after my bind, I also tried it with &&
> sed and that did not work. Both of course remove the sed from history and not
> the clear. I guess I could remove the 2nd to last line. But before I go that sed
> route is there a cleaner way to prevent a command from going to the HISTFILE?
>
> Ken

you can use HISTCONTROL=ignoredups so you would have only one entry for "clear"
in your history

Reply | Threaded
Open this post in threaded view
|

Re: Keeping clear out of history

Alexander Hall


On July 31, 2018 9:09:05 AM GMT+02:00, Solene Rapenne <[hidden email]> wrote:

>Ken M <[hidden email]> wrote:
>> OK, so confession 1, I am a long time bash user
>> confession 2 all of my ksh experience is on solaris
>>
>> However in a when in Rome moment I am realizing how much I like ksh
>in openbsd,
>> but one minor thing. I don't like how much clear ends up in my
>history file. So
>> I am wondering what I can do to suppress a command going to history.
>>
>>
>> Lets put my .profile here for reference
>>
>> # $OpenBSD: dot.profile,v 1.5 2018/02/02 02:29:54 yasuoka Exp $
>> #
>> # sh/ksh initialization
>>
>> . /etc/ksh.kshrc
>>
>>
>PATH=$HOME/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin:/usr/games:$HOME/.local/bin
>> PS1="[\u@\h: \W]$ "
>> HISTFILE=$HOME/.ksh_history
>> HISTSIZE=1000
>> export PATH HOME TERM PS1 HISTFILE HISTSIZE
>>
>> # For now clearing out clear from history when starting
>> sed -i '/^clear$/d' $HISTFILE
>>
>> bind -m '^L'=clear'^J'
>> # I wish this worked
>> # bind -m '^L'=clear'^J';sed -i '$d' $HISTFILE
>>
>> alias ll='ls -l'
>> alias la='ls -la'
>> alias watch='gnuwatch'
>>
>>
>> As you can see I tried adding the ; sed after my bind, I also tried
>it with &&
>> sed and that did not work. Both of course remove the sed from history
>and not
>> the clear. I guess I could remove the 2nd to last line. But before I
>go that sed
>> route is there a cleaner way to prevent a command from going to the
>HISTFILE?
>>
>> Ken
>
>you can use HISTCONTROL=ignoredups so you would have only one entry for
>"clear"
>in your history

That, or

  HISTCONTROL=ignorespace

and prefix your clear with a space.

Another obvious candidate is

  bind ^L=clear-screen

which however I believe is still only available in -current.

/Alexander

Reply | Threaded
Open this post in threaded view
|

Re: Keeping clear out of history

Ken MacKenzie
Thanks all for not making me feel like I opened a flame war can of worms.

I think the ignore dups solution is probably the most sensible for my purposes
from what I have read from all the responses.

Thank you.

Ken

Reply | Threaded
Open this post in threaded view
|

Re: Keeping clear out of history

Ken MacKenzie
In reply to this post by Anton Lindqvist-2
> Check out HISTCONTROL[1] and ignorespace in particular. Adding something
> along the lines to your ~/.kshrc should do the trick:
>
>   HISTCONTROL=ignorespace
>   bind -m '^L'='^U clear^J^Y' # note the intentional space before clear
>
> [1] https://man.openbsd.org/ksh#HISTCONTROL

Actually this worked out to be the cleanest for my purposes. Again thank you.

Ken