Compare commits

...

1 Commits

Author SHA1 Message Date
Johannes Altmanninger
233355bc9b __fish_apropos: assume only /usr/bin/apropos is broken
Also, remove a macOS version check that's doom to obsolescence,
and extract a function (WIP).
2025-11-15 14:33:55 +01:00
4 changed files with 19 additions and 7 deletions

View File

@@ -38,7 +38,7 @@ complete -c man -n 'string match -q -- "*/*" (commandline -t | string collect)'
if command -q man
# We have a conditionally-defined man function,
# so we need to check for existence here.
if echo | MANPAGER=cat command man -l - &>/dev/null
if echo | __fish_without_manpager command man -l - &>/dev/null
complete -c man -s l -l local-file -d "Local file" -r
end
end

View File

@@ -5,9 +5,7 @@ if not type -q apropos
exit
end
# Check for macOS Catalina or above.
if test (__fish_uname) = Darwin
and test (string match -r "^\d+" "$(uname -r)") -ge 19
and test -x /usr/libexec/makewhatis
set -l dir
@@ -18,6 +16,11 @@ if test (__fish_uname) = Darwin
end
function __fish_apropos -V dir
if test "$(command -v apropos)" != /usr/bin/apropos
__fish_without_manpager apropos "$argv"
return
end
# macOS 10.15 "Catalina" has a read only filesystem where the whatis database should be.
# The whatis database is non-existent, so apropos tries (and fails) to create it every time,
# which can take seconds.
@@ -34,17 +37,19 @@ if test (__fish_uname) = Darwin
set age (path mtime -R -- $whatis)
end
MANPATH="$dir" MANPAGER=cat WHATISPAGER=cat apropos "$argv"
MANPATH="$dir" __fish_without_manpager apropos "$argv"
if test $age -ge $max_age
test -d "$dir" || mkdir -m 700 -p $dir
/bin/sh -c '( "$@" ) >/dev/null 2>&1 </dev/null &' -- /usr/libexec/makewhatis -o "$whatis" (/usr/bin/manpath | string split : | xargs realpath)
/bin/sh -c '( "$@" ) >/dev/null 2>&1 </dev/null &' -- \
/usr/libexec/makewhatis -o "$whatis" \
(/usr/bin/manpath | string split : | xargs realpath)
end
end
else
function __fish_apropos
# we only ever prefix match for completions. This also ensures results for bare apropos <TAB>
# (apropos '' gives no results, but apropos '^' lists all manpages)
MANPAGER=cat WHATISPAGER=cat apropos "$argv"
__fish_without_manpager apropos "$argv"
end
end

View File

@@ -10,7 +10,7 @@ function __fish_print_help --description "Print help for the specified fish func
end
set -l args -l (path filter -- $man1/$item.1 $man1/$item.1.gz)[1]
# Work around macOS/FreeBSD man not supporting -l yet (only mandoc really needs it).
if not MANPAGER=cat WHATISPAGER=cat command man -l $args[2] &>/dev/null
if not __fish_without_manpager command man -l $args[2] &>/dev/null
set -e args[1]
end
command man $args

View File

@@ -0,0 +1,7 @@
function __fish_without_manpager
MANPAGER=cat WHATISPAGER=cat if test "$argv[1]" = command
command $argv[2..]
else
$argv
end
end