aboutsummaryrefslogtreecommitdiffhomepage
path: root/share/functions/__fish_complete_suffix.fish
diff options
context:
space:
mode:
authorGravatar axel <axel@liljencrantz.se>2007-01-31 01:26:31 +1000
committerGravatar axel <axel@liljencrantz.se>2007-01-31 01:26:31 +1000
commit418192b312756be19868290054cee6a49dc59f8f (patch)
tree120bbd34c35547000de4b8492b70aeaaa439f260 /share/functions/__fish_complete_suffix.fish
parent76d9051605c9a5e0f80a441b5398c4fb02d508e7 (diff)
Make the first and last argument to __fish_complete_suffix optional. Use mimedb to look up descriptions if not supplied.
darcs-hash:20070130152631-ac50b-24f1c947d88ce3ad20f31a17b58adfe02cf002e2.gz
Diffstat (limited to 'share/functions/__fish_complete_suffix.fish')
-rw-r--r--share/functions/__fish_complete_suffix.fish34
1 files changed, 30 insertions, 4 deletions
diff --git a/share/functions/__fish_complete_suffix.fish b/share/functions/__fish_complete_suffix.fish
index b3003553..035911a7 100644
--- a/share/functions/__fish_complete_suffix.fish
+++ b/share/functions/__fish_complete_suffix.fish
@@ -1,13 +1,39 @@
#
# Find files that complete $argv[1], has the suffix $argv[2], and
-# output them as completions with description $argv[3]
+# output them as completions with the description $argv[3] Both
+# $argv[1] and $argv[3] are optional, if only one is specified, it is
+# assumed to be the argument to complete.
#
function __fish_complete_suffix -d "Complete using files"
- set comp $argv[1]
- set suff $argv[2]
- set desc $argv[3]
+ # Variable declarations
+
+ set -l comp
+ set -l suff
+ set -l desc
+ set -l files
+
+ switch (count $argv)
+
+ case 1
+ set comp (commandline -ct)
+ set suff $argv
+ set desc (mimedb -d $suff)
+
+ case 2
+ set comp $argv[1]
+ set suff $argv[2]
+ set desc (mimedb -d $suff)
+
+ case 2
+ set comp $argv[1]
+ set suff $argv[2]
+ set desc $argv[2]
+
+ end
+
+ # Perform the completion
set base (echo $comp |sed -e 's/\.[a-zA-Z0-9]*$//')
eval "set files $base*$suff"