File: __fish_contains_opt.fish

package info (click to toggle)
fish 3.1.2-3%2Bdeb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 38,672 kB
  • sloc: ansic: 80,259; cpp: 47,069; javascript: 17,087; sh: 6,163; python: 3,429; makefile: 669; perl: 367; objc: 78; xml: 18
file content (48 lines) | stat: -rw-r--r-- 1,077 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
function __fish_contains_opt -d "Checks if a specific option has been given in the current commandline"
    set -l next_short
    set -l short_opt
    set -l long_opt

    for i in $argv
        if test -n "$next_short"
            set next_short
            set -a short_opt $i
        else
            switch $i
                case -s
                    set next_short 1
                case '-*'
                    echo __fish_contains_opt: Unknown option $i >&2
                    return 1
                case '*'
                    set -a long_opt $i
            end
        end
    end

    for i in $short_opt
        if test -z "$i"
            continue
        end

        if string match -qr -- "^-$i|^-[^-]*$i" (commandline -cpo)
            return 0
        end

        if string match -qr -- "^-$i|^-[^-]*$i" (commandline -ct)
            return 0
        end
    end

    for i in $long_opt
        if test -z "$i"
            continue
        end

        if contains -- --$i (commandline -cpo)
            return 0
        end
    end

    return 1
end