fish-shell/share/functions/__fish_contains_opt.fish

49 lines
1.1 KiB
Fish
Raw Normal View History

function __fish_contains_opt -d "Checks if a specific option has been given in the current commandline"
set -l next_short
set -l short_opt
set -l long_opt
for i in $argv
2017-04-14 06:13:55 +00:00
if test -n "$next_short"
set next_short
set short_opt $short_opt $i
else
switch $i
case -s
set next_short 1
case '-*'
2017-04-14 06:13:55 +00:00
echo __fish_contains_opt: Unknown option $i >&2
return 1
2017-04-14 06:13:55 +00:00
case '*'
set long_opt $long_opt $i
end
end
end
for i in $short_opt
2017-04-14 06:13:55 +00:00
if test -z "$i"
continue
end
2017-04-14 06:13:55 +00:00
if string match -qr -- "^-$i|^-[^-]*$i" (commandline -cpo)
return 0
end
2017-04-14 06:13:55 +00:00
if string match -qr -- "^-$i|^-[^-]*$i" (commandline -ct)
return 0
end
end
for i in $long_opt
2017-04-14 06:13:55 +00:00
if test -z "$i"
continue
end
if contains -- --$i (commandline -cpo)
return 0
end
end
return 1
end