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"
|
2010-09-18 10:18:26 +08:00
|
|
|
set -l next_short
|
2006-02-08 17:20:05 +08:00
|
|
|
|
|
|
|
set -l short_opt
|
2010-09-18 10:18:26 +08:00
|
|
|
set -l long_opt
|
2006-02-08 17:20:05 +08:00
|
|
|
|
|
|
|
for i in $argv
|
2010-09-18 10:18:26 +08:00
|
|
|
if test $next_short
|
|
|
|
set next_short
|
2006-12-13 04:37:27 +08:00
|
|
|
set short_opt $short_opt $i
|
2006-02-08 17:20:05 +08:00
|
|
|
else
|
|
|
|
switch $i
|
|
|
|
case -s
|
|
|
|
set next_short 1
|
|
|
|
case '-*'
|
|
|
|
echo __fish_contains_opt: Unknown option $i
|
|
|
|
return 1
|
|
|
|
|
|
|
|
case '**'
|
2006-12-13 04:37:27 +08:00
|
|
|
set long_opt $long_opt $i
|
2006-02-08 17:20:05 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
for i in $short_opt
|
|
|
|
|
|
|
|
if test -z $i
|
|
|
|
continue
|
|
|
|
end
|
|
|
|
|
2006-11-29 22:00:04 +08:00
|
|
|
if commandline -cpo | sgrep -- "^-"$i"\|^-[^-]*"$i >/dev/null
|
2006-02-08 17:20:05 +08:00
|
|
|
return 0
|
|
|
|
end
|
2010-09-18 10:18:26 +08:00
|
|
|
|
2006-11-29 22:00:04 +08:00
|
|
|
if commandline -ct | sgrep -- "^-"$i"\|^-[^-]*"$i >/dev/null
|
2006-02-08 17:20:05 +08:00
|
|
|
return 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
for i in $long_opt
|
|
|
|
if test -z $i
|
|
|
|
continue
|
|
|
|
end
|
|
|
|
|
|
|
|
if contains -- --$i (commandline -cpo)
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return 1
|
|
|
|
end
|
|
|
|
|