# bash completion for ddt have ddt && _ddt() { local cur prev COMPREPLY=() #_get_comp_words_by_ref cur prev cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" case $prev in -b|--bootp) local showlist=$(ddt show-pxe --no-header|awk '{print $1}') COMPREPLY=($(compgen -W "${showlist}" -- "$cur")) return 0 ;; -d|-s|--sector) local showlist=$(ddt show-sector --no-header|awk '{print $1}') COMPREPLY=($(compgen -W "${showlist}" -- "$cur")) return 0 ;; -p|--pool) local showlist=$(ddt show-pool --no-header|awk '{print $1}') COMPREPLY=($(compgen -W "${showlist}" -- "$cur")) return 0 ;; -k|--kind) COMPREPLY=($(compgen -W "dhcp pool-dhcp fix-address" -- "$cur")) return 0 ;; -t|--tag) local showlist=$(ddt show-tag --no-header|awk '{print $1}') COMPREPLY=($(compgen -W "${showlist}" -- "$cur")) return 0 ;; esac if [[ "$cur" == '-*' || $COMP_CWORD -gt 1 ]] then COMPREPLY=($(compgen -W "$(ddt help|grep "^ ddt ${COMP_WORDS[1]}"|sed -e 's/[\[]/\n/g;'|grep -- '^-'|cut -f 1 -d ']'|cut -f 1 -d ' '|sed -e 's/|/ /g;'|xargs echo -n)" -- "$cur")) else COMPREPLY=($(compgen -W "$($(which ddt||echo /usr/local/bin/ddt) help|grep '^ ddt'|awk '{print $2}'|xargs echo -n)" -- "$cur")) fi } && complete -F _ddt ddt have dhcp-dns-tools && complete -F _ddt dhcp-dns-tools