2025-09-29 09:30:35 +02:00
|
|
|
# localization: skip(uses-apropos)
|
|
|
|
|
|
2019-03-09 13:39:51 -08:00
|
|
|
# If seq is not installed, then define a function that invokes __fish_fallback_seq
|
2015-11-27 19:34:27 +01:00
|
|
|
# We can't call type here because that also calls seq
|
2013-01-12 15:22:09 -08:00
|
|
|
|
2025-09-29 11:57:41 +02:00
|
|
|
if command -sq seq
|
|
|
|
|
exit
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if command -sq gseq
|
|
|
|
|
# No seq provided by the OS, but GNU coreutils was apparently installed, fantastic
|
2025-09-29 09:30:35 +02:00
|
|
|
function seq
|
2025-09-29 11:57:41 +02:00
|
|
|
gseq $argv
|
2016-11-27 21:27:22 -08:00
|
|
|
end
|
2025-09-29 11:57:41 +02:00
|
|
|
exit
|
|
|
|
|
end
|
2016-11-27 21:27:22 -08:00
|
|
|
|
2025-09-29 11:57:41 +02:00
|
|
|
# No seq command
|
2025-09-29 09:30:35 +02:00
|
|
|
function seq
|
2025-09-29 11:57:41 +02:00
|
|
|
__fish_fallback_seq $argv
|
|
|
|
|
end
|
2016-11-27 21:27:22 -08:00
|
|
|
|
2025-09-29 09:30:35 +02:00
|
|
|
function __fish_fallback_seq
|
2025-09-29 11:57:41 +02:00
|
|
|
set -l from 1
|
|
|
|
|
set -l step 1
|
|
|
|
|
set -l to 1
|
2019-11-16 11:21:45 +01:00
|
|
|
|
2025-09-29 11:57:41 +02:00
|
|
|
# Remove a "--" argument if it happens first.
|
|
|
|
|
if test "x$argv[1]" = x--
|
|
|
|
|
set -e argv[1]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
switch (count $argv)
|
|
|
|
|
case 1
|
|
|
|
|
set to $argv[1]
|
|
|
|
|
case 2
|
|
|
|
|
set from $argv[1]
|
|
|
|
|
set to $argv[2]
|
|
|
|
|
case 3
|
|
|
|
|
set from $argv[1]
|
|
|
|
|
set step $argv[2]
|
|
|
|
|
set to $argv[3]
|
|
|
|
|
case '*'
|
2025-09-29 09:30:35 +02:00
|
|
|
printf "seq: Expected 1, 2 or 3 arguments, got %d\n" (count $argv) >&2
|
2025-09-29 11:57:41 +02:00
|
|
|
return 1
|
|
|
|
|
end
|
2016-11-27 21:27:22 -08:00
|
|
|
|
2025-09-29 11:57:41 +02:00
|
|
|
for i in $from $step $to
|
|
|
|
|
if not string match -rq -- '^-?[0-9]*([0-9]*|\.[0-9]+)$' $i
|
2025-09-29 09:30:35 +02:00
|
|
|
printf "seq: '%s' is not a number\n" $i >&2
|
2025-09-29 11:57:41 +02:00
|
|
|
return 1
|
2016-11-27 21:27:22 -08:00
|
|
|
end
|
2025-09-29 11:57:41 +02:00
|
|
|
end
|
2016-11-27 21:27:22 -08:00
|
|
|
|
2025-09-29 11:57:41 +02:00
|
|
|
if test $step -ge 0
|
|
|
|
|
set -l i $from
|
|
|
|
|
while test $i -le $to
|
|
|
|
|
echo $i
|
|
|
|
|
set i (math -- $i + $step)
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
set -l i $from
|
|
|
|
|
while test $i -ge $to
|
|
|
|
|
echo $i
|
|
|
|
|
set i (math -- $i + $step)
|
2016-11-27 21:27:22 -08:00
|
|
|
end
|
|
|
|
|
end
|
2013-01-12 15:22:09 -08:00
|
|
|
end
|