fork/fish-shell

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

Johannes AltmanningerMark private functions that don't need localizationa53db7256

master
1.3 KiB48 linesraw
1# localization: skip(private)
2function __fish_cache_sourced_completions
3    # Allow a `--name=foo` option which ends up in the filename.
4    argparse -s name= -- $argv
5    or return
6
7    set -q argv[1]
8    or return 1
9
10    set -l cmd (command -s $argv[1])
11    or begin
12        # If we have no command, we can't get an mtime
13        # and so we can't cache
14        # The caller can more easily retry
15        return 127
16    end
17
18    set -l cachedir (__fish_make_cache_dir completions)
19    or return
20
21    set -l stampfile $cachedir/$argv[1].stamp
22    set -l compfile $cachedir/$argv[1].fish
23
24    set -l mtime (path mtime -- $cmd)
25
26    set -l cmtime 0
27    path is -rf -- $stampfile
28    and read cmtime <$stampfile
29
30    # If either the timestamp or the completion file don't exist,
31    # or the mtime differs, we rerun.
32    #
33    # That means we'll rerun if the command was up- or downgraded.
34    if path is -vrf -- $stampfile $compfile || test "$cmtime" -ne "$mtime" 2>/dev/null
35        __fish_cache_put $compfile
36        $argv >$compfile
37        # If the command exited unsuccessfully, we assume it didn't work.
38        or return 2
39        __fish_cache_put $stampfile
40        echo -- $mtime >$stampfile
41    end
42
43    if path is -rf -- $compfile
44        source $compfile
45        return 0
46    end
47    return 3
48end