aboutsummaryrefslogtreecommitdiffhomepage
path: root/init/functions/contains.fish
diff options
context:
space:
mode:
authorGravatar axel <axel@liljencrantz.se>2006-02-08 20:20:43 +1000
committerGravatar axel <axel@liljencrantz.se>2006-02-08 20:20:43 +1000
commit35dde5de15be1fa36d42c995c82ca5f083e99225 (patch)
treeee10cfa925413b348a2c329c0f200675900a006e /init/functions/contains.fish
parent4d9bb19467c72204e0bba5d71f1625a5fad587db (diff)
Move more functions to autoload
darcs-hash:20060208102043-ac50b-4e26615523a6b9528c2ea4768f41ad1b2e1c4a0f.gz
Diffstat (limited to 'init/functions/contains.fish')
-rw-r--r--init/functions/contains.fish49
1 files changed, 49 insertions, 0 deletions
diff --git a/init/functions/contains.fish b/init/functions/contains.fish
new file mode 100644
index 00000000..76694608
--- /dev/null
+++ b/init/functions/contains.fish
@@ -0,0 +1,49 @@
+#
+# This file defines various shellscript functions. Most of them are
+# meant to be used directly by the user, but some of them, typically
+# the ones whose name start with '__fish_', are only meant to be used
+# internally by fish.
+#
+
+function contains -d "Test if a key is contained in a set of values"
+ while set -q argv
+ switch $argv[1]
+ case '-h' '--h' '--he' '--hel' '--help'
+ 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[$i]
+ help contains
+ return 1
+
+ case '*'
+ # End the loop, we found the key
+ break
+
+ end
+ set -e argv[1]
+ end
+
+ if not set -q argv
+ 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|grep -Fx -- $key >/dev/null
+ return $status
+end
+
+