bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Feature: Easily remove current command from history


From: Dennis Williamson
Subject: Re: Feature: Easily remove current command from history
Date: Mon, 4 Jan 2016 16:35:17 -0600



On Mon, Jan 4, 2016 at 4:05 PM, Dennis Williamson <dennistwilliamson@gmail.com> wrote:


On Mon, Jan 4, 2016 at 3:07 PM, Eduardo A. Bustamante López <dualbus@gmail.com> wrote:
Take into account that many options have been provided (history -d, the space
prefix, even editing .bash_history yourself).

But you request a single key stroke to do this... why?

If you enter a password by mistake in your shell, and it gets recorded, then
you go and clean up. It's not hard to do.

But since you request a simple-and-easy way of doing this, it seems like you do
this a lot... which you shouldn't! :-)

Now, it is up to you to convince Chet that it is so important to have a simple
shortcut to do this. IMO, it isn't.

--
Eduardo Bustamante
https://dualbus.me/



Just bind your own keystroke to a function which uses history -d:

histdel() {
    local last_command histline

    last_command=$(history 1)

    histline="${last_command%  *}"

    history -d "$histline"    #  I wish history -d accepted negative offsets
}

bind -x '"\ez": histdel'

Then Esc-z or Alt-z will delete the most recent history entry. You could choose another keystroke to bind.


--
Visit serverfault.com to get your system administration questions answered.

Actually, this is better:

histdel() {

    (    #  use a subshell to make extglob setting and function variables local

    last_command=$(history 1)

    #  strip modified-entry marker, it doesn't matter if we delete an asterisk in the command since we're deleting it anyway
    last_command=${last_command/\*/ }
    shopt -s extglob
    last_command=${last_command##*( )}  # strip leading spaces
    histline="${last_command%%  *}"

    history -d "$histline"    #  I wish history -d accepted negative offsets

    )
}

bind -x '"\ez": histdel'

I'm using a subshell here. You can use the local keyword for variables and save and restore the extglob setting if you prefer.

--
Visit serverfault.com to get your system administration questions answered.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]