Skip to content

Instantly share code, notes, and snippets.

@hirose31
Created March 17, 2009 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hirose31/80579 to your computer and use it in GitHub Desktop.
Save hirose31/80579 to your computer and use it in GitHub Desktop.
# -*- mode: sh -*-
shopt -s extglob progcomp
## commandのあとにファイルをとるタイプ
_command_file() {
local cur prev
local commands="$1"
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
# do not attempt completion if we're specifying an option
[ "$cur" == -* ] && return 0
#echo "cur:$cur prev:$prev" >&2
# first parameter on line or first since an option?
if [ $COMP_CWORD = 1 ] || [[ "$prev" == -* ]]; then
COMPREPLY=( $( compgen -W "$commands" $cur ))
fi
return 0
}
## daemontools
_daemonup() {
local cur
cur=${COMP_WORDS[$COMP_CWORD]}
if [ -d "$SYS_HOME" ]; then
DAEMONDIR=$SYS_HOME/daemon;
else
DAEMONDIR=/usr/irori/daemon;
fi
WORDS=$(ls -1 $DAEMONDIR)
COMPREPLY=( $(compgen -W "$WORDS" -- "$cur") )
}
complete -F _daemonup daemonup
_daemondown() {
local cur
cur=${COMP_WORDS[$COMP_CWORD]}
WORDS=$(ls -1 /service)
COMPREPLY=( $(compgen -W "$WORDS" -- "$cur") )
}
complete -F _daemondown daemondown
complete -F _daemondown taitailf
complete -F _daemondown tailess
## gisty
_gisty() {
_command_file "list post private_post sync sync_delete pull_all help"
}
complete -F _gisty -o default gisty
## openssl
_openssl() {
_command_file "asn1parse ca ciphers crl crl2pkcs7 dgst dh dhparam dsa dsaparam enc engine errstr gendh gendsa genrsa nseq ocsp passwd pkcs12 pkcs7 pkcs8 prime rand req rsa rsautl s_client s_server s_time sess_id smime speed spkac verify version x509"
}
complete -F _openssl -o default openssl
### xen
_xm() {
_command_file "create console shutdown block-attach block-detach block-list list"
}
complete -F _xm -o default xm
### freeipmi
ipmi_host=
for ((i=101; i<=116; i++)); do
ipmi_host="$ipmi_host $(printf 'mi%03d' $i)"
done
_ipmi_general() {
local cur prev
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
local ipmi_user="admin"
local ipmi_workaround="authcap authcap,solpayloadsize"
local ipmi_general_opts="-h -u -p -P --config-file -W"
local ipmi_opts="$ipmi_general_opts $@"
#echo "cur:$cur prev:$prev" >&2
case $prev in
-u)
COMPREPLY=($( compgen -W "$ipmi_user" -- $cur ))
;;
-h)
COMPREPLY=($( compgen -W "$ipmi_host" -- $cur ))
;;
--config-file)
COMPREPLY=($( compgen -f -- $cur ))
;;
-W)
COMPREPLY=($( compgen -W "$ipmi_workaround" -- $cur ))
;;
*)
COMPREPLY=($( compgen -W "$ipmi_opts" -- $cur ))
;;
esac
return 0
}
_ipmi_ping() {
local cur prev
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
local my_opts="-c"
case $prev in
-c)
COMPREPLY=($( compgen -W "5 10 30" -- $cur ))
;;
*)
case "${COMP_WORDS[*]}" in
*-@(c)*)
COMPREPLY=($( compgen -W "$ipmi_host" -- $cur ))
;;
*)
COMPREPLY=($( compgen -W "$my_opts $ipmi_host" -- $cur ))
;;
esac
;;
esac
}
_ipmi_power() {
local my_opts="--on --off --reset --stat --on-if-off"
_ipmi_general "$my_opts"
}
_ipmi_bmcconfig() {
local cur prev
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
local my_opts="--checkout --commit --diff"
case $prev in
--checkout)
COMPREPLY=($( compgen -W "--section" -- $cur ))
;;
--@(commit|diff))
COMPREPLY=($( compgen -W "--key-pair" -- $cur ))
;;
--section|-S)
COMPREPLY=($( compgen -W "User1 User2 User3 Lan_Conf SOL_Conf" -- $cur ))
;;
--key-pair|-e)
case $cur in
\"User[123]*)
u=${cur:1:5}
w=
for p in Username= Enable_User=yes Password= Password20=; do
w="$w $u:$p"
done
COMPREPLY=($( compgen -W "$w" -- $cur ))
;;
\"Lan_Conf*)
w=
for p in IP_Address Subnet_Mask Default_Gateway_IP_Address; do
w="$w Lan_Conf:$p"
done
COMPREPLY=($( compgen -W "$w" -- $cur ))
;;
\"SOL_Conf*)
w=
for p in Enable_SOL SOL_Privilege_Level=Administrator Non_Volatile_Bit_Rate=19200/38400/57600/115200 Volatile_Bit_Rate=; do
w="$w SOL_Conf:$p"
done
COMPREPLY=($( compgen -W "$w" -- $cur ))
;;
*)
COMPREPLY=($( compgen -P '"' -W 'User1: User2: User3: Lan_Conf Lan_Conf: SOL_Conf SOL_Conf:' $cur ))
;;
esac
;;
*)
_ipmi_general "$my_opts"
;;
esac
}
complete -F _ipmi_general ipmi-sensors
complete -F _ipmi_general ipmiconsole
complete -F _ipmi_ping ipmiping
complete -F _ipmi_power ipmipower
complete -F _ipmi_bmcconfig bmc-config
## Tokyo Cabinet
_tchmgr() {
local cur prev
local commands="create inform put out get list optimize importtsv version"
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
create)
COMPREPLY=($( compgen -W "-td -tb X.tc" -- $cur ))
;;
inform|put|out|get|list|importtsv)
COMPREPLY=($( compgen -W "-nl -nb" -- $cur ) \
$( compgen -f -X '!*.tc?(h)' -- $cur ) \
$( compgen -d -- $cur ))
;;
optimize)
COMPREPLY=($( compgen -W "-td -tb" -- $cur ) \
$( compgen -f -X '!*.tc?(h)' -- $cur ) \
$( compgen -d -- $cur ))
;;
-*)
COMPREPLY=($( compgen -f -X '!*.tc?(h)' -- $cur ) \
$( compgen -d -- $cur ))
;;
*)
# pathの次
case $arg1 in
create|optimize)
COMPREPLY=($( compgen -W "bnum" -- $cur ))
;;
put|out|get)
COMPREPLY=($( compgen -W "key" -- $cur ))
;;
bnum)
;;
esac
;;
esac
fi
}
complete -F _tchmgr tchmgr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment