fork/fish-shell

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

Johannes AltmanningerPrepare to not localize private function descriptionsd835c5252

master
1.5 KiB68 linesraw
1# localization: skip(uses-apropos)
2
3# If seq is not installed, then define a function that invokes __fish_fallback_seq
4# We can't call type here because that also calls seq
5
6if command -sq seq
7    exit
8end
9
10if command -sq gseq
11    # No seq provided by the OS, but GNU coreutils was apparently installed, fantastic
12    function seq
13        gseq $argv
14    end
15    exit
16end
17
18# No seq command
19function seq
20    __fish_fallback_seq $argv
21end
22
23function __fish_fallback_seq
24    set -l from 1
25    set -l step 1
26    set -l to 1
27
28    # Remove a "--" argument if it happens first.
29    if test "x$argv[1]" = x--
30        set -e argv[1]
31    end
32
33    switch (count $argv)
34        case 1
35            set to $argv[1]
36        case 2
37            set from $argv[1]
38            set to $argv[2]
39        case 3
40            set from $argv[1]
41            set step $argv[2]
42            set to $argv[3]
43        case '*'
44            printf "seq: Expected 1, 2 or 3 arguments, got %d\n" (count $argv) >&2
45            return 1
46    end
47
48    for i in $from $step $to
49        if not string match -rq -- '^-?[0-9]*([0-9]*|\.[0-9]+)$' $i
50            printf "seq: '%s' is not a number\n" $i >&2
51            return 1
52        end
53    end
54
55    if test $step -ge 0
56        set -l i $from
57        while test $i -le $to
58            echo $i
59            set i (math -- $i + $step)
60        end
61    else
62        set -l i $from
63        while test $i -ge $to
64            echo $i
65            set i (math -- $i + $step)
66        end
67    end
68end