|
From: | Dennis Williamson |
Subject: | Re: Feature: Easily remove current command from history |
Date: | Tue, 5 Jan 2016 11:40:30 -0600 |
Actually, this is better: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 histlinelast_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.histdel() {( # use a subshell to make extglob setting and function variables locallast_command=$(history 1)# strip modified-entry marker, it doesn't matter if we delete an asterisk in the command since we're deleting it anywaylast_command=${last_command/\*/ }shopt -s extgloblast_command=${last_command##*( )} # strip leading spaceshistline="${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.
[Prev in Thread] | Current Thread | [Next in Thread] |