8000 `history delete --exact --case-sensitive` doesn't save to disk until the user runs a second command · Issue #10066 · fish-shell/fish-shell · GitHub
[go: up one dir, main page]

Skip to content
< 8000 div id="repo-content-pjax-container" class="repository-content " >

history delete --exact --case-sensitive doesn't save to disk until the user runs a second command #10066

@alexwlchan

Description

@alexwlchan
  • fish, version 3.6.1
  • macOS Ventura 13.5
  • iTerm 2: Build 3.4.21
  • Running sh -c 'env HOME=$(mktemp -d) XDG_CONFIG_HOME= fish' doesn't affect anything

I've been playing around with the history delete function a bit, and discovered something surprising: if I use --exact --case-sensitive, changes don't propagate to the fish_history until after I run another command. It's possible that I'm doing something wrong, but I think what I'm doing is pretty reasonable.

If a user tries to delete a command from history with --exact --case-sensitive and then closes their session, the deletion will not be saved to their fish_history file.

Steps to reproduce

  1. Open a new shell session

  2. Run the following lines, which run a command and then delete it from history:

    $ echo "my password is hunter2"
    $ history delete --exact --case-sensitive 'echo "my password is hunter2"'
  3. Close the session

  4. Open a new shell session

  5. Type echo

I expect that fish won't suggest the echo "my password is hunter2" command, because I've deleted it from the history. But what actually happens is that it gets suggested!

Observations

  • This doesn't reproduce if I run an extra command between steps 3 and 4. This command doesn't have to do anything interesting – true is plenty.

  • I can reproduce if I use builtin history delete instead of history delete.

  • This doesn't reproduce if I search the history to delete the offending command. Something like:

    $ echo "my password is hunter2"
    my password is hunter2
    
    $ history delete
    Search term: hunter2
    [1] echo "my password is hunter2"
    [2] history delete --exact --case-sensitive 'echo "my password is hunter2"'
    
    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? > 1
    
    Deleting history entry 1: "echo "my password is hunter2""

    If I start typing echo in a new command, I don't get the offending command suggested.

  • As far as I can tell, the change doesn't seem to be making it to my fish_history file until after I run the next command. Let's step through it in a clean session with sh -c 'env HOME=$(mktemp -d) XDG_CONFIG_HOME= fish':

    1. First I’ll open the fish_history file in an external editor, so I can see what it looks like after each command:

      $ mate "$HOME/.local/share/fish/fish_history"
      - cmd: mate "$HOME/.local/share/fish/fish_history"
        when: 1697835968
    2. Run the echo command:

      $ echo "my password is hunter2"
      - cmd: mate "$HOME/.local/share/fish/fish_history"
        when: 1697835968
      - cmd: echo "my password is hunter2"
        when: 1697835997
    3. Try to delete that last command from history:

      $ history delete --exact --case-sensitive 'echo "my password is hunter2"'
      - cmd: mate "$HOME/.local/share/fish/fish_history"
        when: 1697835968
      - cmd: echo "my password is hunter2"
        when: 1697835997
      - cmd: history delete --exact --case-sensitive 'echo "my password is hunter2"'
        when: 1697836030

      Notice that both the deleted command and the history delete command are still in the history.

      If I close my session here, the supposedly deleted command will persist.

    4. Now run any other command:

      $ true
      - cmd: mate "$HOME/.local/share/fish/fish_history"
        when: 1697835968
      - cmd: history delete --exact --case-sensitive 'echo "my password is hunter2"'
        when: 1697836030
      - cmd: true
        when: 1697836073

      Notice that the command I tried to delete in step iii has now been purged from the history.

  • For comparison, here's what happens if I do an interactive search for items to delete, as before in a new shell:

    1. Open the fish_history file in an external editor:

      $ mate "$HOME/.local/share/fish/fish_history"
      - cmd: mate "$HOME/.local/share/fish/fish_history"
        when: 1697836363
    2. Run the echo command:

      $ echo "my password is hunter2"
      - cmd: mate "$HOME/.local/share/fish/fish_history"
        when: 1697836363
      - cmd: echo "my password is hunter2"
        when: 1697836376
    3. Run history delete with a search query of hunter2, and ask it to delete the single item which it finds:

      $ history delete
      Search term: hunter2
      [1] echo "my password is hunter2"
      
      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? > 1
      
      Deleting history entry 1: "echo "my password is hunter2"
      - cmd: mate "$HOME/.local/share/fish/fish_history"
        when: 1697836363
      - cmd: history delete
        when: 1697836403

      Notice that the offending command has already been scrubbed from the history.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething that's not working as intended

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0