michael@0: function _mach() michael@0: { michael@0: local cur cmds c subcommand michael@0: COMPREPLY=() michael@0: michael@0: # Load the list of commands michael@0: cmds=`"${COMP_WORDS[0]}" mach-commands` michael@0: michael@0: # Look for the subcommand. michael@0: cur="${COMP_WORDS[COMP_CWORD]}" michael@0: subcommand="" michael@0: c=1 michael@0: while [ $c -lt $COMP_CWORD ]; do michael@0: word="${COMP_WORDS[c]}" michael@0: for cmd in $cmds; do michael@0: if [ "$cmd" = "$word" ]; then michael@0: subcommand="$word" michael@0: fi michael@0: done michael@0: c=$((++c)) michael@0: done michael@0: michael@0: if [[ "$subcommand" == "help" || -z "$subcommand" ]]; then michael@0: COMPREPLY=( $(compgen -W "$cmds" -- ${cur}) ) michael@0: fi michael@0: michael@0: return 0 michael@0: } michael@0: complete -o default -F _mach mach