# bash completion for ipmitool -*- shell-script -*- proc _ipmitool_singleline_help { setglobal COMPREPLY = '( '$( compgen -W "$( $1 $2 2>&1 | \ sed -ne 's/[,\r]//g' -e 's/^.*[Cc]ommands://p' )" -- "$cur" ) ) } proc _ipmitool { var cur = '', prev = '', words = '', cword = '' _init_completion || return match $prev { with -h|-V|-p|-U|-e|-k|-y|-P|-m|-b|-t|-B|-T|-l return 0 with -d setglobal COMPREPLY = '( '$( compgen -W "$( \ command ls -d /dev/ipmi* /dev/ipmi/* /dev/ipmidev/* \ 2>/dev/null | sed -ne 's/^[^0-9]*\([0-9]\{1,\}\)/\1/p' )" \ -- "$cur" ) ) return 0 with -I setglobal COMPREPLY = '( '$( compgen -W "$( $1 -h 2>&1 | \ sed -e '/^Interfaces:/,/^[[:space:]]*$/!d' \ -ne 's/^[[:space:]]\{1,\}\([^[:space:]]\{1,\}\).*/\1/p' )" \ -- "$cur" ) ) return 0 with -H _known_hosts_real $cur return 0 with -f|-S|-O _filedir return 0 with -C setglobal COMPREPLY = '( '$( compgen -W '{0..14}' -- "$cur" ) ) return 0 with -L setglobal COMPREPLY = '( '$( compgen -W 'CALLBACK USER OPERATOR ADMINISTRATOR' \ -- "$cur" ) ) return 0 with -A setglobal COMPREPLY = '( '$( compgen -W 'NONE PASSWORD MD2 MD5 OEM' -- "$cur" ) ) return 0 with -o setglobal COMPREPLY = '( '$( compgen -W "$( $1 -o list 2>&1 | \ awk '/^[ \t]+/ { print $1 }' ) list" -- "$cur" ) ) return 0 } if [[ "$cur" == -* ]] { setglobal COMPREPLY = '( '$( compgen -W '$( _parse_help "$1" -h)' -- "$cur" ) ) return 0 } # Find out command and subcommand var cmds = '( 'raw i2c spd lan chassis power event mc sdr sensor fru gendev sel pef sol tsol isol user channel session sunoem kontronoem picmg fwum firewall shell exec set hpm ekanalyzer) var i = '', c = '', cmd = '', subcmd = '' for (( i=1; i < ${#words[@]}-1; i++ )); do [[ -n $cmd ]] && subcmd=${words[i]} && break for c in ${cmds[@]}; do [[ ${words[i]} == $c ]] && cmd=$c && break done done if [[ -z $cmd ]] { setglobal COMPREPLY = '( '$( compgen -W '${cmds[@]}' -- "$cur" ) ) return 0 } # Command/subcommand completions match $cmd { with shell with exec _filedir with chassis|power|kontronoem|fwum _ipmitool_singleline_help $1 $cmd with lan match $subcmd { with print|set with alert [[ $prev == alert ]] && \ setglobal COMPREPLY = '( '$( compgen -W 'print set' -- "$cur" ) ) with stats [[ $prev == stats ]] && \ setglobal COMPREPLY = '( '$( compgen -W 'print set' -- "$cur" ) ) with * setglobal COMPREPLY = '( '$( compgen -W 'print set alert stats' \ -- "$cur" ) ) } with sdr match $subcmd { with get|info|type|list|entity with elist setglobal COMPREPLY = '( '$( compgen -W 'all full compact event mclog fru generic' -- "$cur" ) ) with dump _filedir with fill match $prev { with fill setglobal COMPREPLY = '( '$( compgen -W 'sensors file' \ -- "$cur" ) ) with file _filedir } with * setglobal COMPREPLY = '( '$( compgen -W 'get info type list elist entity dump fill' -- "$cur" ) ) } with sensor match $subcmd { with list|get|thresh with * setglobal COMPREPLY = '( '$( compgen -W 'list get thresh' -- "$cur" ) ) } with sel match $subcmd { with info|clear|list|elist|delete with add|save|writeraw|readraw _filedir with time [[ $prev == time ]] && \ setglobal COMPREPLY = '( '$( compgen -W 'get set' -- "$cur" ) ) with * setglobal COMPREPLY = '( '$( compgen -W 'info clear list elist delete add get save writeraw readraw time' -- "$cur" ) ) } with user match $subcmd { with summary|list|disable|enable|priv|test with set [[ $prev == set ]] && \ setglobal COMPREPLY = '( '$( compgen -W 'name password' -- "$cur" ) ) with * setglobal COMPREPLY = '( '$( compgen -W 'summary list set disable enable priv test' -- "$cur" ) ) } with set [[ $prev == set ]] && \ setglobal COMPREPLY = '( '$( compgen -W 'hostname username password privlvl authtype localaddr targetaddr port csv verbose' \ -- "$cur" ) ) } } && complete -F _ipmitool ipmitool # ex: ts=4 sw=4 et filetype=sh