-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
- 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
-
Open a new shell session
-
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"'
-
Close the session
-
Open a new shell session
-
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 –
trueis plenty. -
I can reproduce if I use
builtin history deleteinstead ofhistory 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
echoin 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_historyfile until after I run the next command. Let's step through it in a clean session withsh -c 'env HOME=$(mktemp -d) XDG_CONFIG_HOME= fish':-
First I’ll open the
fish_historyfile 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
-
Run the
echocommand:$ echo "my password is hunter2"- cmd: mate "$HOME/.local/share/fish/fish_history" when: 1697835968 - cmd: echo "my password is hunter2" when: 1697835997
-
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 deletecommand are still in the history.If I close my session here, the supposedly deleted command will persist.
-
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:
-
Open the
fish_historyfile in an external editor:$ mate "$HOME/.local/share/fish/fish_history"- cmd: mate "$HOME/.local/share/fish/fish_history" when: 1697836363
-
Run the
echocommand:$ echo "my password is hunter2"- cmd: mate "$HOME/.local/share/fish/fish_history" when: 1697836363 - cmd: echo "my password is hunter2" when: 1697836376
-
Run
history deletewith a search query ofhunter2, 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.
-