You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Feature Request: Interactively delete history entries during auto-completion (i.e. via Alt-Del) #2110
Fish auto-completion is great, but the history can be easily bloated with wrong & unwanted entries
I'm aware about history --contains keyword --delete and the interactive history editor via fish_config but find them rather cumbersome.
It would be great to have i.e. a key combination like [Alt-Del] or [Ctrl-Del] to remove the current completion proposal from the history
Reacted by Johannes Wienke, Bulkan Evcimen, albi.eth, Geoffrey Mon, Chris Clark, somedadaism, Tyler Jones, MCMic, Justin Kaeser, Dror Levin and 19 more
The "current completion proposal" is not added to the interactive command history. You have to actually execute a command for it to be added to the history. By that time it's far too late for a key binding to have any effect.
@bentolor Can you provide more details about your scenario? Perhaps by creating a asciinema recording?
I think maybe there is a misunderstanding with what he's asking for - the "proposal" I think he's referring to is the completion (edit: probably the autosuggestion you'd see) fish is proposing that the user would be rejecting, as I read it.
So I suspect he's wanting to be able to hit alt-del to nuke what he sees suggested from history, or while searching history (with the up arrow), remove the current entry from history. It'd essentially cause a history --contains <COMMAND LINE CONTENTS> --delete which would (could) show the interactive prompt.
The interactive deletion is important because the desired (undesired) history item may not be the first result due to the context-sensitive nature of autosuggestions and the builtin's inability to do queries on those variables. Deleting the up-arrow stuff and deleting a autosuggestion after accepting it with the right arrow key, could obviously be hacked in today because you have the full result of the completion and the accepted autosuggestion in the buffer to search with (after they activate it).
So I suspect he's wanting to be able to hit alt-del to nuke what he sees suggested from history, or while searching history with the up arrow remove the current entry from history.
You nailed it!
$ wget http://user:[email protected]/ ...
# Argh! Missed to type a leading space. My pw is stored
# --- Option #1:
$ [arrow-up] # shows last command
$ [Alt-Del] # Clears commandline & removes entry from history
# --- Option #2:
$ mysecret[arrow-up] # shows last command matching string
$ [Alt-Del] # Removes entry from history. Suggest next history match
$ mysecret[arrow-up] # ..nothing happens (last element).
This is a cool idea. We could even do it without confirmation - just have to report the command we deleted, so the user can copy and paste it if they want to reinstate it.
Okay, that makes sense. In retrospect I should have grokked that from the original comment. And this is the first really good example I've seen for why fish should continue to have a way to delete individual history entries. Now we just need to make that mechanism robust.
There are also some details to be worked out with regard to this proposal. For example, should the current command line be cleared? Should we also bind [alt-backspace]?
P.S., [ctrl-del] can't be done because [del] is already a control character. It's as if you tried to bind \c\cH (where \ch is the [backspace] key); the [ctrl] key modifies the next character it doesn't send a character in its own right. But [alt-del] or [meta-del] is certainly possible.
For example, should the current command line be cleared?
Thought about this, too. On the plus side, this could make sense, because otherwise the user needs to switch to a different key-combination to clear the line after his cleanup. On the negative side this could suprise the user, as the semantic of the key combination changes on the last history match.
So I'd say "no" and would be fine with the case that after typing --passwd mypass followed by [Up-Arrow] and as many [Alt]-[Del] until nothing more happens and then switch over into hammering [Alt]-[Backspace] or [Backspace] as long as required to clear the line, because I do not know any better.
Should we also bind [alt-backspace]?
For me [Backspace] is clearly bound to editing the line I'm on and currently seems to act as "delete last word" which IMHO is perfectly appropriate. So would leave [alt-backspace] untouched.
But [alt-del] or [meta-del] is certainly possible.
[alt-del] sounds fine and as the most intuitive option to me.
@floam Interesting idea. But many user errors will not cause an exit code indicating it. Others might return exit codes because the operation failed, but not the command syntax (i.e. git push on outdated branches).
So I still think the feature to easily heal/delete completions would offer the biggest "bang" for the "bucks".
I added the following code to my ~.config/fish/config.fish:
function delete-current-history-search
if commandline --search-mode
history --delete (commandline)
commandline -f history-search-backward
end
end
function fish_user_key_bindings
bind \e\[3\;3~ delete-current-history-search
end
Currently testing. But so far it looks pretty good, @jinliu ! Thanks.
@jinliu If you delete the last history element, nothing visible happens. The command is erased from history, though. This might be confusing for the user.
Probably the best solution in this case would be, to revert to the characters the user originally entered (and which are highlighted on history search matches)
Probably the best solution in this case would be, to revert to the characters the user originally entered (and which are highlighted on history search matches)
Agree. But I guess this (and deleting autosuggestion history matches) must be done in C code.
Since fish v3.0 the proposed script no longer works :-( : Even if the expression results only in one matching entry, history delete seems to display an interactive dialog anyway. Did not find any means to make this silently:
ben@notebook ~ $ docker push gitlab:4567/open-source/docker-bambooagent:77e8f0b7a032ea8754aa3ef7446451c2e49eb939[1] docker push gitlab:4567/open-source/docker-bambooagent:77e8f0b7a032ea8754aa3ef7446451c2e49eb939
Enter nothing to cancel the delete, or
Enter one or more of the entry IDs separated by a space, or
Enter "all" to delete all the matching entries.
Delete which entries? >
Thanks, this improves the situation. Unfortunately but no longer to the full beauty it IMHO previously did: After pressing [Alt]-[Del], the commandline -f history-search-backward shows the next entry. But on pressing ↓-Key, it appears again.
It's deleted from history, though: After pressing Ctrl-C and restarting, the deleted entry no longer appears.
Maybe we should record the exit code in history? Note: this is probably tricky - we'd need to go back and alter the record after the job completes.
This was wrong - we do not add the item to history until after the command completes. So it would not be difficult to store the exit status in history. However the exit status of an arbitrary command may indicate a failure: we would need to tell fish about commands where that actually is the case - with complete perhaps. And it would be confusing for the items to not be in history just because they failed - presumably you want to use history to go and try the command again with a small adjustment. So it would have to just affect autosuggestions I think.
presumably you want to use history to go and try the command again with a small adjustment.
This scenario immediately came into my mind. I think this is a very common pattern
In those cases: After your adjustment was successful, you really want to drop the other command, because it will now continues to deceive and confront you with the same error over and over again.
So it would have to just affect auto-suggestions I think.
Doe fish auto-purge/expire history entries?
Nevertheless, storing the exit code of commands and offering a „delete all failed commands from history“ sounds great to me.
Reacted by Alex Bennée, Emre Şafak, Raphael and rusty kay
Unfortunately #9515 does not work with a pager. I have fzf installed via omf, which obstructs the deletion feature inside the history.
After resurrection the [Alt]-[Del] binding with the updated script from jinliu (note to myself: working copy below), I'm still very much in favour of that inline approach.
As CLI program, fish obviously has hit a quite hard & early limit on the UX features, which are discoverable by users on their own. I think that's unfortunate. Would love something like a "fish tip" oneliner as startup prompt.
function delete-current-history-search
ifcommandline--search-mode
history delete --exact--case-sensitive (commandline)
commandline-f history-search-backward
endend# Alt-Delfunction fish_user_key_bindings
bind\e\[3\;3~ delete-current-history-search
end
I have fzf installed via OMG, which obstructs the deletion feature inside the history.
you can tell your external pager to run any arbitrary shell command, which allows you to delete the current item
function delete-current-history-search
this implementation looks strictly worse than the builtin version, although I agree that we should prefer to implement this in fish script rather than rust source code. It should be kind of possible today to reach feature parity but I'm not sure
Activity
ridiculousfish commentedon Jun 1, 2015
That's a good idea!
krader1961 commentedon Jul 21, 2016
The "current completion proposal" is not added to the interactive command history. You have to actually execute a command for it to be added to the history. By that time it's far too late for a key binding to have any effect.
@bentolor Can you provide more details about your scenario? Perhaps by creating a asciinema recording?
floam commentedon Jul 21, 2016
@krader1961 Why would the item need to be added to history again?
floam commentedon Jul 21, 2016
I think maybe there is a misunderstanding with what he's asking for - the "proposal" I think he's referring to is the completion (edit: probably the autosuggestion you'd see) fish is proposing that the user would be rejecting, as I read it.
floam commentedon Jul 21, 2016
So I suspect he's wanting to be able to hit alt-del to nuke what he sees suggested from history, or while searching history (with the up arrow), remove the current entry from history. It'd essentially cause a
history --contains <COMMAND LINE CONTENTS> --deletewhich would (could) show the interactive prompt.The interactive deletion is important because the desired (undesired) history item may not be the first result due to the context-sensitive nature of autosuggestions and the builtin's inability to do queries on those variables. Deleting the up-arrow stuff and deleting a autosuggestion after accepting it with the right arrow key, could obviously be hacked in today because you have the full result of the completion and the accepted autosuggestion in the buffer to search with (after they activate it).
bentolor commentedon Jul 21, 2016
You nailed it!
ridiculousfish commentedon Jul 22, 2016
This is a cool idea. We could even do it without confirmation - just have to report the command we deleted, so the user can copy and paste it if they want to reinstate it.
krader1961 commentedon Jul 22, 2016
Okay, that makes sense. In retrospect I should have grokked that from the original comment. And this is the first really good example I've seen for why fish should continue to have a way to delete individual history entries. Now we just need to make that mechanism robust.
There are also some details to be worked out with regard to this proposal. For example, should the current command line be cleared? Should we also bind [alt-backspace]?
P.S., [ctrl-del] can't be done because [del] is already a control character. It's as if you tried to
bind \c\cH(where\chis the [backspace] key); the [ctrl] key modifies the next character it doesn't send a character in its own right. But [alt-del] or [meta-del] is certainly possible.bentolor commentedon Jul 22, 2016
Thought about this, too. On the plus side, this could make sense, because otherwise the user needs to switch to a different key-combination to clear the line after his cleanup. On the negative side this could suprise the user, as the semantic of the key combination changes on the last history match.
So I'd say "no" and would be fine with the case that after typing
--passwd mypassfollowed by[Up-Arrow]and as many[Alt]-[Del]until nothing more happens and then switch over into hammering[Alt]-[Backspace]or[Backspace]as long as required to clear the line, because I do not know any better.For me [Backspace] is clearly bound to editing the line I'm on and currently seems to act as "delete last word" which IMHO is perfectly appropriate. So would leave [alt-backspace] untouched.
[alt-del] sounds fine and as the most intuitive option to me.
bentolor commentedon Jul 22, 2016
@krader1961
Another use-case I have is that I'm still unable to remember if it is
git rev-parse @orgit parse-rev @(no working autocompletion on that).After doing it wrong only one time the fish history deceives and annoys me so much, that I start to edit the history over and over again.
As I still cannot tell you which one of the both word git is expecting, this game will be ongoing for me for an indefinite time ;-)
floam commentedon Jul 22, 2016
Maybe we should record the exit code in history? Note: this is probably tricky - we'd need to go back and alter the record after the job completes.
bentolor commentedon Jul 22, 2016
@floam Interesting idea. But many user errors will not cause an exit code indicating it. Others might return exit codes because the operation failed, but not the command syntax (i.e.
git pushon outdated branches).So I still think the feature to easily heal/delete completions would offer the biggest "bang" for the "bucks".
2 remaining items
bentolor commentedon Aug 24, 2016
I added the following code to my
~.config/fish/config.fish:Currently testing. But so far it looks pretty good, @jinliu ! Thanks.
bentolor commentedon Aug 24, 2016
@jinliu If you delete the last history element, nothing visible happens. The command is erased from history, though. This might be confusing for the user.
Probably the best solution in this case would be, to revert to the characters the user originally entered (and which are highlighted on history search matches)
jinliu commentedon Aug 24, 2016
Agree. But I guess this (and deleting autosuggestion history matches) must be done in C code.
bentolor commentedon Jan 11, 2019
Since fish v3.0 the proposed script no longer works :-( : Even if the expression results only in one matching entry,
history deleteseems to display an interactive dialog anyway. Did not find any means to make this silently:zanchey commentedon Jan 26, 2019
Try
history delete --exact --case-sensitive (commandline).bentolor commentedon Jan 27, 2019
Thanks, this improves the situation. Unfortunately but no longer to the full beauty it IMHO previously did: After pressing
[Alt]-[Del], thecommandline -f history-search-backwardshows the next entry. But on pressing↓-Key, it appears again.It's deleted from history, though: After pressing
Ctrl-Cand restarting, the deleted entry no longer appears.floam commentedon Jan 27, 2019
This was wrong - we do not add the item to history until after the command completes. So it would not be difficult to store the exit status in history. However the exit status of an arbitrary command may indicate a failure: we would need to tell fish about commands where that actually is the case - with
completeperhaps. And it would be confusing for the items to not be in history just because they failed - presumably you want to use history to go and try the command again with a small adjustment. So it would have to just affect autosuggestions I think.bentolor commentedon Jan 28, 2019
This scenario immediately came into my mind. I think this is a very common pattern
In those cases: After your adjustment was successful, you really want to drop the other command, because it will now continues to deceive and confront you with the same error over and over again.
Doe fish auto-purge/expire history entries?
Nevertheless, storing the exit code of commands and offering a „delete all failed commands from history“ sounds great to me.
faho commentedon Feb 16, 2024
This is handled by #9515, which allows it in the history pager, where it's clearer that there's a history context.
bentolor commentedon Oct 16, 2024
Unfortunately #9515 does not work with a pager. I have
fzfinstalled viaomf, which obstructs the deletion feature inside the history.After resurrection the
[Alt]-[Del]binding with the updated script from jinliu (note to myself: working copy below), I'm still very much in favour of that inline approach.As CLI program, fish obviously has hit a quite hard & early limit on the UX features, which are discoverable by users on their own. I think that's unfortunate. Would love something like a "fish tip" oneliner as startup prompt.
krobelus commentedon Oct 16, 2024
you can tell your external pager to run any arbitrary shell command, which allows you to delete the current item
this implementation looks strictly worse than the builtin version, although I agree that we should prefer to implement this in fish script rather than rust source code. It should be kind of possible today to reach feature parity but I'm not sure