mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-30 06:03:49 +08:00
7492b6cdb3
darcs-hash:20070116012918-ac50b-c1c0df64333ad910ca81dbc86ad193ece6680722.gz
44 lines
760 B
Fish
44 lines
760 B
Fish
|
|
function contains --description "Test if a key is contained in a set of values"
|
|
while count $argv >/dev/null
|
|
switch $argv[1]
|
|
case '-h' '--h' '--he' '--hel' '--help'
|
|
__fish_print_help contains
|
|
return
|
|
|
|
case '--'
|
|
# End the loop, the next argument is the key
|
|
set -e argv[1]
|
|
break
|
|
|
|
case '-*'
|
|
printf (_ "%s: Unknown option '%s'\n") contains $argv[1]
|
|
__fish_print_help contains >&2
|
|
return 1
|
|
|
|
case '*'
|
|
# End the loop, we found the key
|
|
break
|
|
|
|
end
|
|
set -e argv[1]
|
|
end
|
|
|
|
if not count $argv >/dev/null
|
|
printf (_ "%s: Key not specified\n") contains
|
|
return 1
|
|
end
|
|
|
|
set key $argv[1]
|
|
set -e argv[1]
|
|
|
|
#
|
|
# Loop through values
|
|
#
|
|
|
|
printf "%s\n" $argv|sgrep -Fx -- $key >/dev/null
|
|
return $status
|
|
end
|
|
|
|
|