fork/fish-shell

git clone https://git.julia.blue/fork/fish-shell

Johannes AltmanningerMerge changes to config paths6d0cd3d9b

master
1.6 KiB50 linesraw
1# localization: skip(private)
2if not type -q apropos
3    function __fish_apropos
4    end
5    exit
6end
7
8if test (__fish_uname) = Darwin
9    and test -x /usr/libexec/makewhatis
10
11    function __fish_apropos
12        # macOS has a read only filesystem where the whatis database should be.
13
14        if functions -q apropos || test "$(command -v apropos)" != /usr/bin/apropos
15            __fish_without_manpager apropos "$argv"
16            return
17        end
18
19        # The whatis database is non-existent, so apropos tries (and fails) to create it every time,
20        # which can take seconds.
21        #
22        # Instead, we build a whatis database in the user cache directory
23        # and override the MANPATH using that directory before we run `apropos`
24        #
25        # the cache is rebuilt once a week.
26        set -l dir (__fish_make_cache_dir apropos)
27        set -l whatis $dir/whatis
28        set -l max_age 600000 # like a week
29        set -l age $max_age
30
31        if test -f "$whatis"
32            set age (path mtime -R -- $whatis)
33        end
34
35        MANPATH="$dir" __fish_without_manpager /usr/bin/apropos "$argv"
36
37        if test $age -ge $max_age
38            set -l sh (__fish_posix_shell)
39            $sh -c '( "$@" ) >/dev/null 2>&1 </dev/null &' -- \
40                /usr/libexec/makewhatis -o "$whatis" \
41                (/usr/bin/manpath | string split : | xargs realpath)
42        end
43    end
44else
45    function __fish_apropos
46        # we only ever prefix match for completions. This also ensures results for bare apropos <TAB>
47        # (apropos '' gives no results, but apropos '^' lists all manpages)
48        __fish_without_manpager apropos "$argv"
49    end
50end