#!/bin/bash _frobnicate () { local cur prev local allargs possibilities cur="${COMP_WORDS[$COMP_CWORD]}" prev="${COMP_WORDS[$(( $COMP_CWORD - 1 ))]}" allargs=" --reporter --assignee -h -v -d --description " if [ "$COMP_CWORD" = 1 ] ; then possibilities="$allargs" # Our previous argument is explicitly one of the # options we support! elif [[ "$allargs" == *" $prev "* ]] ; then # Our previous option expects an arbitrary string # No autocomplete is possible if [ "$prev" = "--description" ] ; then return # they want help? try to get them to hit 'enter' now elif [ "$prev" = "-h" ] ; then return # Our previous option was one of the options # that does not take any value, so all options # are on the table elif [ "$prev" = "-v" -o "$prev" = "-d" ] ; then possibilities="$allargs" # Our previous option expects a username elif [ "$prev" = "--reporter" -o "$prev" = "--assignee" ] ; then possibilities=$(getent passwd | awk -F: '$3 > 1000 {print $1}') fi else possibilities="$allargs" fi if [ -n "$possibilities" ] ; then COMPREPLY=( $(compgen -W "$possibilities" -- "$cur" ) ) fi } complete -F _frobnicate frobnicate