mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00:00
bd18736ee5
Using bare vars is more efficient because it makes the builtin `math` expression cache more useful. That's because if you prefix each var with a dollar-sign then the fish parser expands it before `math` is run. Something like `math x + 1` can be cached since the expression is the same each time it is run. But if you do `math $x + 1` and x==1 then you're effectively executing `math 1 + 1`. And if x==2 the next time then you're running `math 2 + 1`. Which makes the expression cache much less effective.
46 lines
1 KiB
Fish
46 lines
1 KiB
Fish
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
|
|
|