1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
# bash completion for quintuple-agent
# Copyright 2005 Hans Ulrich Niedermann <debian@n-dimensional.de>
# License: GNU GPL v2 or later
# * only handle completion for q-client
# * handles all the common cases
# * does not complete IDs for put, TTLs, and query parameters
# * allows undefined combinations (stuff like having the same option twice)
# * but it still is very useful
have q-client &&
_q-client()
{
COMPREPLY=()
local cur prev
cur=${COMP_WORDS[COMP_CWORD]}
prev="${COMP_WORDS[COMP_CWORD-1]}"
local commands options
commands="put get delete list"
options="-d --debug --help --version"
options="${options} -i --insure -q --query-options -t --time-to-live"
# the command itself
if [ "x$prev" = "xq-client" ]; then
COMPREPLY=($( compgen -W "$commands $options" -- "$cur" ))
return 0
fi
# if extglob is on, accept all numbers as TTL
if [ "$(shopt extglob | cut -f2)" = "on" ] &&
[ "x$prev" = "x-t" -o "x$prev" = "x--time-to-live" ]
then
case "$cur" in
+([[:digit:]]))
COMPREPLY=("$cur")
return 0
;;
esac
fi
COMPREPLY=()
# walk through the options and commands
case "$prev" in
get|delete)
# list stored items
local items
items=($(q-client list 2>&1 | cut -f1))
if [ "$?" -eq 0 ]; then
# only if we could connect to q-agent process
COMPREPLY=($( compgen -W "${items[*]}" -- "$cur"))
fi
;;
list)
;;
put)
;;
--help)
;;
--version)
;;
-i|--insure)
COMPREPLY=($( compgen -W "put ${options}" -- "$cur"))
;;
-d|--debug)
COMPREPLY=($( compgen -W "${commands} ${options}" -- "$cur"))
;;
*)
# unhandled, i.e. TTL or query option string
if [ "$COMP_CWORD" -ge 2 ]; then
local pprev
pprev="${COMP_WORDS[COMP_CWORD-2]}"
case "$pprev" in
-q|--query-options)
COMPREPLY=($( compgen -W "put ${options}" -- "$cur"))
;;
-t|--time-to-live)
COMPREPLY=($( compgen -W "put ${options}" -- "$cur"))
;;
esac
fi
;;
esac
return 0
}
[ "$have" ] && complete -F _q-client q-client
|