fork/fish-shell

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

Johannes AltmanningerMark private functions that don't need localizationa53db7256

master
1.1 KiB49 linesraw
1# localization: skip(private)
2function __fish_contains_opt -d "Checks if a specific option has been given in the current commandline"
3    set -l next_short
4    set -l short_opt
5    set -l long_opt
6
7    for i in $argv
8        if test -n "$next_short"
9            set next_short
10            set -a short_opt $i
11        else
12            switch $i
13                case -s
14                    set next_short 1
15                case '-*'
16                    echo __fish_contains_opt: Unknown option $i >&2
17                    return 1
18                case '*'
19                    set -a long_opt $i
20            end
21        end
22    end
23
24    for i in $short_opt
25        if test -z "$i"
26            continue
27        end
28
29        if string match -qr -- "^-$i|^-[^-]*$i" (commandline -cpx)
30            return 0
31        end
32
33        if string match -qr -- "^-$i|^-[^-]*$i" (commandline -ct)
34            return 0
35        end
36    end
37
38    for i in $long_opt
39        if test -z "$i"
40            continue
41        end
42
43        if contains -- --$i (commandline -cpx)
44            return 0
45        end
46    end
47
48    return 1
49end