File: contains_seq.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 (46 lines) | stat: -rw-r--r-- 1,061 bytes parent folder | download | duplicates (2)
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
function contains_seq --description 'Return true if array contains a sequence'
    set -l printnext
    switch $argv[1]
        case --printnext
            set printnext[1] 1
            set -e argv[1]
    end
    set -l pattern
    set -l string
    set -l dest pattern
    for i in $argv
        if test "$i" = --
            set dest string
            continue
        end
        set $dest $$dest $i
    end
    set -l nomatch 1
    set -l i 1
    for s in $string
        if set -q printnext[2]
            return 0
        end
        if test "$s" = "$pattern[$i]"
            set -e nomatch[1]
            set i (math $i + 1)
            if not set -q pattern[$i]
                if set -q printnext[1]
                    set printnext[2] 1
                    continue
                end
                return 0
            end
        else
            if not set -q nomatch[1]
                set nomatch 1
                set i 1
            end
        end
    end
    if set -q printnext[1]
        echo ''
    end
    set -q printnext[2]
end