FISH_SHOULD_ADD_TO_HISTORY(1)
π FISH_SHOULD_ADD_TO_HISTORY π
okay bestie, so this is a page from the fish-shell manual, and honestly? it's giving "tiny function, huge power." let's get into it β¨
πΈ NAME πΈ
fish_should_add_to_history β the lil' decider of whether a command gets to be added to the history π
π¦ SYNOPSIS π¦
fish_should_add_to_history
function fish_should_add_to_history
...
end
π DESCRIPTION π
so the fish_should_add_to_history function gets executed right before fish adds a command to history, and its return status is literally the whole vibe check β that's what decides whether it happens or not π
if it returns 0, the command is stored in history. when it returns anything else, it is not. and in that latter case, ngl, the command can still be recalled for one command π (so it's not gone-gone, just not archived, iykyk).
the first argument to fish_should_add_to_history is the commandline. and here's the kinda surprising part: history is added before a command is run, so likeβ¦ e.g. status <#envvar-status> can't be checked. π the reason for this ordering is so that commands that don't finish β like exec β execute command in current process <> β and long-running commands are available in new sessions immediately. iconic behavior, honestly.
and now the plot twist: if fish_should_add_to_history doesn't exist, fish will save a command to history unless it starts with a space. but if it does exist, this function takes over all of the duties β so commands starting with space are saved unless fish_should_add_to_history says otherwise. periodt π
β EXAMPLE β
a simple example, bestie:
function fish_should_add_to_history
for cmd in vault mysql ls
string match -qr "^$cmd" -- $argv; and return 1
end
return 0
end
this refuses to store any immediate "vault", "mysql" or "ls" calls. and note: commands starting with space would be stored (because the function has taken over, remember? π«Ά).
and here's a second one that's extremely relatable:
function fish_should_add_to_history
# I don't want `git pull`s in my history when I'm in a specific repository
if string match -qr '^git pull' -- "$argv"
and string match -qr "^/home/me/my-secret-project/" -- (pwd -P)
return 1
end
return 0
end
π Copyright π
fish-shell developers
k that's the whole page, mwah π this was fish-shell version 4.9, dated Sep 08, 2026 β go forth and curate your history like the main character you are ππ
π¦ where this page comes from
- arch rolling: fish 4.9.3-1 Β· GPL-2.0-only AND BSD-3-Clause AND ISC AND MIT AND PSF-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms