Two things are happening here:
- fish's
alias actually creates a function. - fish ships with a default history function already.
So when you write
alias history "PAGER='bat -l fish' history"
what you actually have is the recursive function
function history PAGER='bat -l fish' history $argv end
Some solutions:
use a different name for your alias
alias hist 'PAGER="bat -l fish" history'
Don't alias _old_history hist, but copy it instead
functions --copy history _old_history alias history 'PAGER="bat -l fish" _old_history'
If you don't care to keep fish's function, invoke the builtin history command in your own function
function history builtin history $argv | bat -l fish end
why doesn't the builtin history support pager?
I assume the fish designers didn't think that was a core part of the history functionality. I assume they put the user-facing stuff in a function that users can override.
Here's the relevant snippet from the default history function:
case search # search the interactive command history test -z "$search_mode" and set search_mode --contains if isatty stdout set -l pager (__fish_anypager) and isatty stdout or set pager cat # If the user hasn't preconfigured less with the $LESS environment variable, # we do so to have it behave like cat if output fits on one screen. if not set -qx LESS set -x LESS --quit-if-one-screen # Also set --no-init for less < v530, see #8157. if type -q less; and test (less --version | string match -r 'less (\d+)')[2] -lt 530 2>/dev/null set -x LESS $LESS --no-init end end not set -qx LV # ask the pager lv not to strip colors and set -x LV -c builtin history search $search_mode $show_time $max_count $_flag_case_sensitive $_flag_reverse $_flag_null -- $argv | $pager else builtin history search $search_mode $show_time $max_count $_flag_case_sensitive $_flag_reverse $_flag_null -- $argv end