2006-02-08 17:20:05 +08:00
|
|
|
function __fish_contains_opt -d "Checks if a specific option has been given in the current commandline"
|
2016-11-28 13:27:22 +08:00
|
|
|
set -l next_short
|
|
|
|
set -l short_opt
|
|
|
|
set -l long_opt
|
|
|
|
|
|
|
|
for i in $argv
|
2017-04-14 14:13:55 +08:00
|
|
|
if test -n "$next_short"
|
2016-11-28 13:27:22 +08:00
|
|
|
set next_short
|
2017-08-05 09:02:24 +08:00
|
|
|
set -a short_opt $i
|
2016-11-28 13:27:22 +08:00
|
|
|
else
|
|
|
|
switch $i
|
|
|
|
case -s
|
|
|
|
set next_short 1
|
|
|
|
case '-*'
|
2017-04-14 14:13:55 +08:00
|
|
|
echo __fish_contains_opt: Unknown option $i >&2
|
2016-11-28 13:27:22 +08:00
|
|
|
return 1
|
2017-04-14 14:13:55 +08:00
|
|
|
case '*'
|
2017-08-05 09:02:24 +08:00
|
|
|
set -a long_opt $i
|
2016-11-28 13:27:22 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
for i in $short_opt
|
2017-04-14 14:13:55 +08:00
|
|
|
if test -z "$i"
|
2016-11-28 13:27:22 +08:00
|
|
|
continue
|
|
|
|
end
|
|
|
|
|
2024-01-22 14:42:45 +08:00
|
|
|
if string match -qr -- "^-$i|^-[^-]*$i" (commandline -cpx)
|
2016-11-28 13:27:22 +08:00
|
|
|
return 0
|
|
|
|
end
|
|
|
|
|
2017-04-14 14:13:55 +08:00
|
|
|
if string match -qr -- "^-$i|^-[^-]*$i" (commandline -ct)
|
2016-11-28 13:27:22 +08:00
|
|
|
return 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
for i in $long_opt
|
2017-04-14 14:13:55 +08:00
|
|
|
if test -z "$i"
|
2016-11-28 13:27:22 +08:00
|
|
|
continue
|
|
|
|
end
|
|
|
|
|
2024-01-22 14:42:45 +08:00
|
|
|
if contains -- --$i (commandline -cpx)
|
2016-11-28 13:27:22 +08:00
|
|
|
return 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return 1
|
2006-02-08 17:20:05 +08:00
|
|
|
end
|