__ppl() { if __ppl_needs_command_name; then COMPREPLY=($(__ppl_suggest_command_name)) return 0 fi if __ppl_needs_contact_id; then COMPREPLY=($(__ppl_suggest_contact_id)) return 0 fi if __ppl_needs_contact_email_address; then COMPREPLY=($(__ppl_suggest_contact_email_address)) return 0 fi if __ppl_needs_contact_nickname; then COMPREPLY=($(__ppl_suggest_contact_nickname)) return 0 fi if __ppl_needs_contact_organization; then COMPREPLY=($(__ppl_suggest_contact_organization)) return 0 fi if __ppl_needs_contact_phone_numher; then COMPREPLY=($(__ppl_suggest_contact_phone_numher)) return 0 fi if __ppl_needs_contact_url; then COMPREPLY=($(__ppl_suggest_contact_url)) return 0 fi if __ppl_needs_git_remote; then COMPREPLY=($(__ppl_suggest_git_remote)) return 0 fi } __ppl_needs_command_name() { if [[ $COMP_CWORD == 1 ]]; then return 0 else return 1 fi } __ppl_needs_contact_id() { command_list=$(__ppl_commands_needing_contact_ids) command_name=${COMP_WORDS[1]} if [[ $command_list =~ $command_name ]] && [[ $COMP_CWORD -eq 2 ]]; then return 0 else return 1 fi } __ppl_needs_git_remote() { command_list=$(__ppl_commands_needing_git_remotes) command_name=${COMP_WORDS[1]} if [[ $command_list =~ $command_name ]] && [[ $COMP_CWORD -eq 2 ]]; then return 0 else return 1 fi } __ppl_needs_contact_email_address() { if [ "${COMP_WORDS[1]}" == "email" ] && [ "$COMP_CWORD" == 3 ]; then return 0 else return 1 fi } __ppl_needs_contact_nickname() { if [ "${COMP_WORDS[1]}" == "nick" ] && [ "$COMP_CWORD" == 3 ]; then return 0 else return 1 fi } __ppl_needs_contact_organization() { if [ "${COMP_WORDS[1]}" == "org" ] && [ "$COMP_CWORD" == 3 ]; then return 0 else return 1 fi } __ppl_needs_contact_phone_numher() { if [ "${COMP_WORDS[1]}" == "phone" ] && [ "$COMP_CWORD" == 3 ]; then return 0 else return 1 fi } __ppl_needs_contact_url() { if [ "${COMP_WORDS[1]}" == "url" ] && [ "$COMP_CWORD" == 3 ]; then return 0 else return 1 fi } __ppl_suggest_command_name() { compgen -W "$(__ppl_commands)" -- ${COMP_WORDS[COMP_CWORD]} } __ppl_suggest_contact_id() { compgen -W "$(__ppl_contact_ids)" -- ${COMP_WORDS[$COMP_CWORD]} } __ppl_suggest_git_remote() { compgen -W "$(__ppl_git_remotes)" -- ${COMP_WORDS[$COMP_CWORD]} } __ppl_suggest_contact_email_address() { contact_id=${COMP_WORDS[2]} compgen -W "$(__ppl_contact_email_addresses $contact_id)" -- ${COMP_WORDS[$COMP_CWORD]} } __ppl_suggest_contact_nickname() { compgen -W "$(__ppl_contact_nicknames ${COMP_WORDS[2]})" -- ${COMP_WORDS[$COMP_CWORD]} } __ppl_suggest_contact_organization() { compgen -W "$(__ppl_contact_organizations ${COMP_WORDS[2]})" -- ${COMP_WORDS[$COMP_CWORD]} } __ppl_suggest_contact_phone_numher() { compgen -W "$(__ppl_contact_phone_numbers ${COMP_WORDS[2]})" -- ${COMP_WORDS[$COMP_CWORD]} } __ppl_suggest_contact_url() { compgen -W "$(__ppl_contact_urls ${COMP_WORDS[2]})" -- ${COMP_WORDS[$COMP_CWORD]} } __ppl_commands_needing_contact_ids() { echo "age" echo "bday" echo "email" echo "mv" echo "name" echo "nick" echo "org" echo "phone" echo "post" echo "rm" echo "show" echo "url" } __ppl_commands_needing_git_remotes() { echo "pull" echo "push" } __ppl_commands() { echo "add" echo "age" echo "bday" echo "completion" echo "email" echo "init" echo "ls" echo "mutt" echo "mv" echo "name" echo "nick" echo "org" echo "phone" echo "post" echo "pull" echo "push" echo "remote" echo "rm" echo "scrape" echo "shell" echo "show" echo "url" echo "version" } __ppl_contact_ids() { ppl nick --no-color | cut -d ':' -f 1 } __ppl_contact_email_addresses() { ppl email $1 } __ppl_contact_nicknames() { ppl nick $1 } __ppl_contact_organizations() { ppl org $1 } __ppl_contact_phone_numbers() { ppl phone $1 } __ppl_contact_urls() { ppl url $1 } __ppl_git_remotes() { ppl remote } complete -F __ppl ppl