_wadm() { local cur prev cmds idx COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" # Get the list of commands (stored in column 1) cmds=(`awk '{print $1}' /etc/bash_completion.d/wadm_commands.txt`) prev="${COMP_WORDS[COMP_CWORD-1]}" # Prev should point to command name and not option idx=1 while [ $idx -lt $COMP_CWORD ] do case "${COMP_WORDS[idx]}" in -*) ;; *) prev="${COMP_WORDS[idx]}"; break;; esac idx=$[idx+1] done # Complete the arguments of the command opts=$(grep ${prev} /etc/bash_completion.d/wadm_commands.txt | awk '{for(i=2;i<=NF;i++) print $i }') case " ${cmds[*]} " in *" $prev "*) COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ); return 0;; esac COMPREPLY=( $(compgen -W "${cmds[*]} opts[*]}" -- ${cur} ) ) return 0 } complete -F _wadm wadm