Skip to content

Instantly share code, notes, and snippets.

@horsepunchkid
Created June 5, 2019 20:46
Show Gist options
  • Save horsepunchkid/8b4e8c37136caea39710371efb5542c6 to your computer and use it in GitHub Desktop.
Save horsepunchkid/8b4e8c37136caea39710371efb5542c6 to your computer and use it in GitHub Desktop.
Bash completion for psql services
_complete_psql() {
services=$(egrep -o '^\[.+\]' ~/.pg_service.conf | cut -f2 -d[ | cut -f1 -d] | sort)
if [[ $services ]]
then
COMPREPLY=( $( compgen -W "$services" -- ${COMP_WORDS[COMP_CWORD]}) )
else
echo
echo "(no services)"
echo -n "> ${COMP_WORDS} "
fi
return 0
}
complete -F _complete_psql psql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment