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