Deleting fish shell history
21st February, 2020
Have you ever made a typo? No, me neither, but in case you ever do…
I run a lot of commands via the shell history using fzf and CTRL-R to save re-typing, and ironically, mispellings. However, if you do mispell something it ends up in the history forevermore, taunting you upon each invocation of fzf-history-widget.
It turns out that fish ships with a neat history command that allows you
to manipulate the history is various ways including searching, deleting, and
completely clearing.
The command I want to remove in this case is mix echo (which should be mix ecto).
I use the --contains option here which will present a prompt showing the
entries and allowing you to delete individual entries or remove all.
$ history delete --contains "mix echo"
[1] history search --contains "mix echo"
[2] mix echo.migrate
[3] mix echo.create
[4] mix echo.reset
[5] mix echo.setup
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.
[I] Delete which entries? >
If you want to search before running delete you can do history search --contains "<search>" which will return a list of items for you to check.