/bash_completion_lib/complete -o default/psql

http://github.com/brinkman83/bashrc · #! · 48 lines · 41 code · 7 blank · 0 comment · 0 complexity · 2ef38334ad67dc6a8efb6beb25453ecb MD5 · raw file

  1. comp_include _filedir _get_cword _known_hosts _pg_databases _pg_users
  2. _psql()
  3. {
  4. local cur prev
  5. COMPREPLY=()
  6. cur=`_get_cword`
  7. prev=${COMP_WORDS[COMP_CWORD-1]}
  8. case "$prev" in
  9. -h|--host)
  10. _known_hosts
  11. return 0
  12. ;;
  13. -U|--username)
  14. _pg_users
  15. return 0
  16. ;;
  17. -d|--dbname)
  18. _pg_databases
  19. return 0
  20. ;;
  21. -@(o|f)|--output|--file)
  22. _filedir
  23. return 0
  24. ;;
  25. esac
  26. if [[ "$cur" == -* ]]; then
  27. # return list of available options
  28. COMPREPLY=( $( compgen -W '-a --echo-all -A --no-align \
  29. -c --command -d --dbname -e --echo-queries \
  30. -E --echo-hidden -f --file -F --filed-separator \
  31. -h --host -H --html -l --list -n -o --output \
  32. -p --port -P --pset -q -R --record-separator \
  33. -s --single-step -S --single-line -t --tuples-only \
  34. -T --table-attr -U --username -v --variable \
  35. -V --version -W --password -x --expanded -X --nopsqlrc \
  36. -? --help ' -- $cur ) )
  37. else
  38. # return list of available databases
  39. _pg_databases
  40. fi
  41. } # _psql()