2025-09-29 09:30:35 +02:00
|
|
|
# localization: skip(private)
|
2020-10-01 15:04:11 +02:00
|
|
|
if not type -q apropos
|
|
|
|
|
function __fish_apropos
|
|
|
|
|
end
|
|
|
|
|
exit
|
|
|
|
|
end
|
|
|
|
|
|
2025-03-05 00:35:54 +01:00
|
|
|
# Check for macOS Catalina or above.
|
|
|
|
|
if test (__fish_uname) = Darwin
|
2025-03-05 14:28:16 +01:00
|
|
|
and test (string match -r "^\d+" "$(uname -r)") -ge 19
|
2021-08-04 18:55:01 +02:00
|
|
|
and test -x /usr/libexec/makewhatis
|
2021-04-01 16:48:32 -07:00
|
|
|
|
2021-04-30 20:09:56 +02:00
|
|
|
set -l dir
|
2021-04-01 16:48:32 -07: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 15:04:11 +02:00
|
|
|
|
2021-04-01 16:48:32 -07: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 20:07:20 +02:00
|
|
|
set -l whatis $dir/whatis
|
2021-04-02 02:08:26 -07:00
|
|
|
set -l max_age 600000 # like a week
|
2020-10-01 15:04:11 +02:00
|
|
|
set -l age $max_age
|
|
|
|
|
|
2021-04-01 16:48:32 -07:00
|
|
|
if test -f "$whatis"
|
2022-07-18 20:39:01 +02:00
|
|
|
set age (path mtime -R -- $whatis)
|
2020-10-01 15:04:11 +02:00
|
|
|
end
|
|
|
|
|
|
2024-10-30 04:33:01 +01:00
|
|
|
MANPATH="$dir" MANPAGER=cat WHATISPAGER=cat apropos "$argv"
|
2020-10-03 17:08:13 -07:00
|
|
|
|
2020-10-01 15:04:11 +02:00
|
|
|
if test $age -ge $max_age
|
2021-04-01 16:48:32 -07:00
|
|
|
test -d "$dir" || mkdir -m 700 -p $dir
|
Orphan background tasks to work around terminals being sensitive to unreaped processes
When a command like "long-running-command &" exits, the resulting SIGCHLD
is queued in the topic monitor. We do not process this signal immediately
but only after e.g. the next command has finished. Only then do we reap the
child process.
Some terminals, such as Terminal.app, refuse to close when there are unreaped
processes associated with the terminal -- as in, having the same session ID,
see setsid(3).
In future, we might want to reap proactively.
For now, apply an isolated workaround: instead of taking care of a child
process, double-fork to create an orphaned process. Since the orphan will
be reaped by PID 1, we can eventually close Terminal.app without it asking
for confirmation.
/bin/sh -c '( "$@" ) >/dev/null 2>&1 &' -- cmd arg1 arg2
This fix confines the problem to the period during which a background process
is running. To complete the fix, we would need to call setsid to detach the
background process from a controlling terminal. That seems to be desirable
however macOS does provide a setsid utility.
setsid cmd arg1 arg2 >/dev/null 2>&1
Fixes #11181
2025-02-28 03:58:51 +01:00
|
|
|
/bin/sh -c '( "$@" ) >/dev/null 2>&1 </dev/null &' -- /usr/libexec/makewhatis -o "$whatis" (/usr/bin/manpath | string split : | xargs realpath)
|
2020-10-01 15:04:11 +02:00
|
|
|
end
|
|
|
|
|
end
|
2021-04-01 16:48:32 -07:00
|
|
|
else
|
|
|
|
|
function __fish_apropos
|
2022-10-28 09:39:43 -07: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 04:33:01 +01:00
|
|
|
MANPAGER=cat WHATISPAGER=cat apropos "$argv"
|
2021-04-01 16:48:32 -07:00
|
|
|
end
|
2020-10-09 18:58:35 +02:00
|
|
|
end
|