Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Interactively delete history entries during auto-completion (i.e. via Alt-Del) #2110

Closed
bentolor opened this issue Jun 1, 2015 · 23 comments

Comments

@bentolor
Copy link

bentolor commented Jun 1, 2015

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

@ridiculousfish ridiculousfish added this to the fish-future milestone Jun 1, 2015
@ridiculousfish
Copy link
Member

That's a good idea!

@krader1961
Copy link
Contributor

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
Copy link
Member

floam commented Jul 21, 2016

@krader1961 Why would the item need to be added to history again?

@floam
Copy link
Member

floam commented 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
Copy link
Member

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

@bentolor
Copy link
Author

bentolor commented 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.

You nailed it!

$ wget http://user:mysecrepass@foo.baz/ ...
                                 # 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).

@ridiculousfish
Copy link
Member

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
Copy link
Contributor

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.

@bentolor
Copy link
Author

bentolor commented Jul 22, 2016

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.

@bentolor
Copy link
Author

bentolor commented Jul 22, 2016

@krader1961

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.

Another use-case I have is that I'm still unable to remember if it is git rev-parse @ or git 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
Copy link
Member

floam commented Jul 22, 2016

After doing it wrong time only one time the fish history deceives and annoys me so much, that I start to edit the history over and over again.

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
Copy link
Author

bentolor commented 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 push on outdated branches).

So I still think the feature to easily heal/delete completions would offer the biggest "bang" for the "bucks".

@jinliu
Copy link
Contributor

jinliu commented Aug 24, 2016

@bentolor Is the following function what you want?

function delete-current-history-search
        if commandline --search-mode
                history --delete (commandline)
                commandline -f history-search-backward
        end
end

This has the problem that when deleting the last match, history-search-backward has no effect, so there's no visual indication of the delete operation.

BTW, how to bind ALT-DEL?

@faho
Copy link
Member

faho commented Aug 24, 2016

BTW, how to bind ALT-DEL?

fish_key_reader is your friend. For my term, I'd have to call bind \e\[3\;3~.

@bentolor
Copy link
Author

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.

@bentolor
Copy link
Author

@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
Copy link
Contributor

jinliu commented Aug 24, 2016

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.

@bentolor
Copy link
Author

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

@zanchey
Copy link
Member

zanchey commented Jan 26, 2019

Try history delete --exact --case-sensitive (commandline).

@bentolor
Copy link
Author

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.

@floam
Copy link
Member

floam commented Jan 27, 2019

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.

@bentolor
Copy link
Author

bentolor commented Jan 28, 2019

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.

@faho
Copy link
Member

faho commented 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.

@faho faho closed this as completed Feb 16, 2024
@faho faho removed this from the fish-future milestone Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants