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

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