Skip to content

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

Closed

Description

@bentolor

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

Activity

  1. added this to the fish-future milestone on Jun 1, 2015
  2. ridiculousfish commented on Jun 1, 2015

    @ridiculousfish
    Member

    That's a good idea!

  3. krader1961 commented on Jul 21, 2016

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

  4. floam commented on Jul 21, 2016

    @floam
    Member

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

  5. floam commented on Jul 21, 2016

    @floam
    Member

    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.

  6. floam commented on Jul 21, 2016

    @floam
    Member

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

  7. bentolor commented on Jul 21, 2016

    @bentolor
    Author

    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).
    
  8. ridiculousfish commented on Jul 22, 2016

    @ridiculousfish
    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.

  9. krader1961 commented on Jul 22, 2016

    @krader1961
    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.

  10. bentolor commented on Jul 22, 2016

    @bentolor
    Author

    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.

  11. bentolor commented on Jul 22, 2016

    @bentolor
    Author

    @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 ;-)

  12. floam commented on Jul 22, 2016

    @floam
    Member

    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.

  13. bentolor commented on Jul 22, 2016

    @bentolor
    Author

    @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".

  14. 2 remaining items

  15. bentolor commented on Aug 24, 2016

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

  16. bentolor commented on Aug 24, 2016

    @bentolor
    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)

  17. jinliu commented on Aug 24, 2016

    @jinliu
    Contributor

    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.

  18. bentolor commented on Jan 11, 2019

    @bentolor
    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? > 
    
  19. zanchey commented on Jan 26, 2019

    @zanchey
    Member

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

  20. bentolor commented on Jan 27, 2019

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

  21. floam commented on Jan 27, 2019

    @floam
    Member

    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.

  22. bentolor commented on Jan 28, 2019

    @bentolor
    Author

    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.

  23. faho commented on Feb 16, 2024

    @faho
    Member

    This is handled by #9515, which allows it in the history pager, where it's clearer that there's a history context.

  24. modified the milestones: fish-future, fish 3.7.0 on Feb 16, 2024
  25. bentolor commented on Oct 16, 2024

    @bentolor
    Author

    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
            if commandline --search-mode
                    history delete --exact --case-sensitive (commandline)
                    commandline -f history-search-backward
            end
    end
    
    # Alt-Del
    function fish_user_key_bindings
        bind \e\[3\;3~ delete-current-history-search
    end
  26. krobelus commented on Oct 16, 2024

    @krobelus
    Contributor

    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

  27. locked as resolved and limited conversation to collaborators on Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions