2020-10-01 13:04:11 +00:00
|
|
|
if not type -q apropos
|
|
|
|
function __fish_apropos
|
|
|
|
end
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
|
2021-04-01 23:48:32 +00:00
|
|
|
# Check for macOS Catalina or above. This is Darwin 19.x or above. See unames reported here:
|
|
|
|
# https://en.wikipedia.org/wiki/Darwin_(operating_system)
|
|
|
|
set -l sysver (uname -sr | string match -r "(Darwin) (\d\d)"\.)
|
|
|
|
|
2021-04-02 14:58:34 +00:00
|
|
|
if test $status -eq 0 -a (count $sysver) -eq 3
|
2021-08-01 16:40:56 +00:00
|
|
|
and test $sysver[2] = Darwin -a $sysver[3] -ge 19
|
2021-08-04 16:55:01 +00:00
|
|
|
and test -x /usr/libexec/makewhatis
|
2021-04-01 23:48:32 +00:00
|
|
|
|
2021-04-30 18:09:56 +00:00
|
|
|
set -l dir
|
2021-04-01 23:48:32 +00:00
|
|
|
if test -n "$XDG_CACHE_HOME"
|
|
|
|
set dir $XDG_CACHE_HOME/fish
|
|
|
|
else
|
|
|
|
set dir (getconf DARWIN_USER_CACHE_DIR)"fish"
|
|
|
|
end
|
2020-10-01 13:04:11 +00:00
|
|
|
|
2021-04-01 23:48:32 +00:00
|
|
|
function __fish_apropos -V dir
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
# Instead, we build a whatis database in the user cache directory
|
|
|
|
# and override the MANPATH using that directory before we run `apropos`
|
|
|
|
#
|
|
|
|
# the cache is rebuilt once a week.
|
2021-04-30 18:07:20 +00:00
|
|
|
set -l whatis $dir/whatis
|
2021-04-02 09:08:26 +00:00
|
|
|
set -l max_age 600000 # like a week
|
2020-10-01 13:04:11 +00:00
|
|
|
set -l age $max_age
|
|
|
|
|
2021-04-01 23:48:32 +00:00
|
|
|
if test -f "$whatis"
|
2022-07-18 18:39:01 +00:00
|
|
|
set age (path mtime -R -- $whatis)
|
2020-10-01 13:04:11 +00:00
|
|
|
end
|
|
|
|
|
2024-10-30 03:33:01 +00:00
|
|
|
MANPATH="$dir" MANPAGER=cat WHATISPAGER=cat apropos "$argv"
|
2020-10-04 00:08:13 +00:00
|
|
|
|
2020-10-01 13:04:11 +00:00
|
|
|
if test $age -ge $max_age
|
2021-04-01 23:48:32 +00:00
|
|
|
test -d "$dir" || mkdir -m 700 -p $dir
|
2024-09-30 01:13:36 +00:00
|
|
|
/usr/libexec/makewhatis -o "$whatis" (/usr/bin/manpath | string split : | xargs realpath) >/dev/null 2>&1 </dev/null &
|
2021-09-23 08:59:44 +00:00
|
|
|
disown $last_pid
|
2020-10-01 13:04:11 +00:00
|
|
|
end
|
|
|
|
end
|
2021-04-01 23:48:32 +00:00
|
|
|
else
|
|
|
|
function __fish_apropos
|
2022-10-28 16:39:43 +00:00
|
|
|
# we only ever prefix match for completions. This also ensures results for bare apropos <TAB>
|
|
|
|
# (apropos '' gives no results, but apropos '^' lists all manpages)
|
2024-10-30 03:33:01 +00:00
|
|
|
MANPAGER=cat WHATISPAGER=cat apropos "$argv"
|
2021-04-01 23:48:32 +00:00
|
|
|
end
|
2020-10-09 16:58:35 +00:00
|
|
|
end
|