Skip to content

Instantly share code, notes, and snippets.

@hirose31
Created May 31, 2011 10:21
Show Gist options
  • Save hirose31/1000270 to your computer and use it in GitHub Desktop.
Save hirose31/1000270 to your computer and use it in GitHub Desktop.
bash completion for Kyoto Cabinet/Tycoon (kchashmgr, ktremotemgr)
# Kyoto Cabinet
_kchashmgr() {
local cur prev
local commands="create inform set remove get list import copy dump load defrag setbulk removebulk getbulk check version" # not include: clear
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
arg1=${COMP_WORDS[1]}
if [ $COMP_CWORD -eq 1 ]; then
COMPREPLY=($( compgen -W "$commands" -- $cur ))
else
case $prev in
-max)
COMPREPLY=($( compgen -W 'num' -- $cur ));;
*.kch)
case $arg1 in
set|setbulk)
COMPREPLY=($( compgen -W "key val" -- $cur ));;
list|remove|get|removebulk|getbulk)
COMPREPLY=($( compgen -W "key" -- $cur ));;
esac
;;
esac
[ ! -z "$COMPREPLY" ] && return
case $arg1 in
create)
COMPREPLY=($( compgen -W "-otr -onl -otl -onr -apow -fpow -ts -tl -tc -bnum X.kch" -- $cur ));;
copy|dump|defrag|check)
COMPREPLY=($( compgen -W "-onl -otl -onr" -- $cur ) \
$( compgen -f -X '!*.kc?(h)' -- $cur ));;
remove|get|import|setbulk|removebulk|getbulk)
COMPREPLY=($( compgen -W "-onl -otl -onr -sx" -- $cur ) \
$( compgen -f -X '!*.kc?(h)' -- $cur ));;
set)
COMPREPLY=($( compgen -W "-onl -otl -onr -sx -add -rep -app -inci -incd" -- $cur ) \
$( compgen -f -X '!*.kc?(h)' -- $cur ));;
list)
COMPREPLY=($( compgen -W "-onl -otl -onr -sx -max" -- $cur ) \
$( compgen -f -X '!*.kc?(h)' -- $cur ));;
inform)
COMPREPLY=($( compgen -W "-onl -otl -onr -st" -- $cur ) \
$( compgen -f -X '!*.kc?(h)' -- $cur ));;
load)
COMPREPLY=($( compgen -W "-otr -onl -otl -onr" -- $cur ) \
$( compgen -f -X '!*.kc?(h)' -- $cur ));;
esac
fi
}
complete -F _kchashmgr kchashmgr
# Kyoto Tycoon
_ktremotemgr() {
local cur prev
local commands="report script tunerepl inform sync set remove get list import vacuum slave setbulk removebulk getbulk" # not include: clear
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
arg1=${COMP_WORDS[1]}
if [ $COMP_CWORD -eq 1 ]; then
COMPREPLY=($( compgen -W "$commands" -- $cur ))
else
case $prev in
-host)
COMPREPLY=($( compgen -W 'localhost kt101 kt102' -- $cur ));;
-port)
COMPREPLY=($( compgen -W '1978 1979 8401 8451 8402 8452' -- $cur ));;
-tout|-mport|-ts|-iv|-xt|-max|-step|-sid)
COMPREPLY=($( compgen -W 'num' -- $cur ));;
-db|-cmd)
COMPREPLY=($( compgen -W 'str' -- $cur ));;
esac
[ ! -z "$COMPREPLY" ] && return
case $arg1 in
report)
COMPREPLY=($( compgen -W "-host -port -tout" -- $cur ));;
inform)
COMPREPLY=($( compgen -W "-host -port -tout -db -st" -- $cur ));;
sync)
COMPREPLY=($( compgen -W "-host -port -tout -db -hard -cmd" -- $cur ));;
set|setbulk)
COMPREPLY=($( compgen -W "-host -port -tout -db -add -rep -app -incr -incd -sx -xt key val" -- $cur ));;
remove|removebulk)
COMPREPLY=($( compgen -W "-host -port -tout -db -sx" -- $cur ));;
get|getbulk)
COMPREPLY=($( compgen -W "-host -port -tout -db -sx -px -pt -pz key" -- $cur ));;
list)
COMPREPLY=($( compgen -W "-host -port -tout -db -des -max -sx -pv -px -pt (key)" -- $cur ));;
import)
COMPREPLY=($( compgen -W "-host -port -tout -db -sx -xt (file)" -- $cur ));;
vacuum)
COMPREPLY=($( compgen -W "-host -port -tout -db -step" -- $cur ));;
slave)
COMPREPLY=($( compgen -W "-host -port -tout -ts -sid -ux -uw -uf -ur" -- $cur ));;
script)
COMPREPLY=($( compgen -W "-host -port -tout -bin proc" -- $cur ));;
tunerepl)
COMPREPLY=($( compgen -W "-host -port -tout -mport -ts -iv (mhost)" -- $cur ));;
esac
fi
}
complete -F _ktremotemgr ktremotemgr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment