fish-shell/share/functions/__fish_anypager.fish
Fabian Boehm ed489d0d52 Add __fish_anypager helper
This makes it easier to get *any pager* in the number of places we do.

Unfortunately:

1. It can't just execute the pager because that might block
2. We can't really set the necessary options for less here
   so they still need to be set outside.

This

Fixes #10074

by falling back to `cat` in that case. We could also decide to abort
instead of using a non-pager, but for history that's probably fine.
2023-11-20 17:16:35 +01:00

32 lines
749 B
Fish

function __fish_anypager --description "Print a pager to use"
set -l pager
# We prefer $PAGER if we have it
set -q PAGER
and echo $PAGER | read -at pager
# or even $MANPAGER if we're allowed to
if test "$argv[1]" = "--with-manpager"
set -q MANPAGER
and echo $MANPAGER | read -at pager
end
# We use them if they *exist*
if command -q $pager[1]
printf %s\n $pager
return 0
end
# Cheesy hardcoded list of pagers.
for cmd in bat lv most less more
if command -q $cmd
echo -- $cmd
return 0
end
end
# We have no pager.
# We could fall back to "cat",
# but in some cases that's probably not helpful.
return 1
end