home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / etc / bash_completion.d / postgresql < prev    next >
Encoding:
Text File  |  2010-11-16  |  3.9 KB  |  164 lines

  1. # bash completion for Postgresql
  2.  
  3. have psql && {
  4. _pg_databases()
  5. {
  6.     return # See https://launchpad.net/bugs/164772
  7.     COMPREPLY=( $( compgen -W "$( psql -l 2>/dev/null | \
  8.         sed -e '1,/^-/d' -e '/^(/,$d' | \
  9.         awk '{print $1}' )" -- "$cur" ) )
  10. }
  11.  
  12. _pg_users()
  13. {
  14.     # See https://launchpad.net/bugs/164772
  15.     #COMPREPLY=( $( psql -qtc 'select usename from pg_user' template1 2>/dev/null | \
  16.     #       command grep "^ $cur" ) )
  17.     #[ ${#COMPREPLY[@]} -eq 0 ] && COMPREPLY=( $( compgen -u -- $cur ) )
  18.     COMPREPLY=( $( compgen -u -- "$cur" ) )
  19. }
  20.  
  21. # createdb(1) completion
  22. #
  23. _createdb()
  24. {
  25.     local cur prev split=false
  26.  
  27.     COMPREPLY=()
  28.     _get_comp_words_by_ref cur prev
  29.  
  30.     _split_longopt && split=true
  31.  
  32.     case $prev in
  33.         -h|--host)
  34.             _known_hosts_real "$cur"
  35.             return 0
  36.             ;;
  37.         -U|--username|-O|--owner)
  38.             _pg_users
  39.             return 0
  40.             ;;
  41.         -p|--port|-D|--tablespace|-E|--encoding|-T|--template)
  42.             # argument required but no completions available
  43.             return 0
  44.             ;;
  45.         --help|--version)
  46.             # all other arguments are noop with these
  47.             return 0
  48.             ;;
  49.     esac
  50.  
  51.     $split && return 0
  52.  
  53.     if [[ "$cur" == -* ]]; then
  54.         COMPREPLY=( $( compgen -W '--tablespace --template --encoding --host \
  55.             --port --username --password --echo --quiet --help --version' \
  56.             -- "$cur" ) )
  57.     else
  58.         _pg_databases
  59.     fi
  60. }
  61. complete -F _createdb -o default createdb
  62.  
  63. # dropdb(1) completion
  64. #
  65. _dropdb()
  66. {
  67.     local cur prev split=false
  68.  
  69.     COMPREPLY=()
  70.     _get_comp_words_by_ref cur prev
  71.  
  72.     _split_longopt && split=true
  73.  
  74.     case $prev in
  75.         -h|--host)
  76.             _known_hosts_real "$cur"
  77.             return 0
  78.             ;;
  79.         -U|--username)
  80.             _pg_users
  81.             return 0
  82.             ;;
  83.         --help|--version)
  84.             # all other arguments are noop with these
  85.             return 0
  86.             ;;
  87.     esac
  88.  
  89.     $split && return 0
  90.  
  91.     if [[ "$cur" == -* ]]; then
  92.         COMPREPLY=( $( compgen -W '--host --port --username --password \
  93.             --interactive --echo --quiet --help --version' -- "$cur" ) )
  94.     else
  95.         _pg_databases
  96.     fi
  97. }
  98. complete -F _dropdb -o default dropdb
  99.  
  100. # psql(1) completion
  101. #
  102. _psql()
  103. {
  104.     local cur prev split=false
  105.  
  106.     COMPREPLY=()
  107.     _get_comp_words_by_ref cur prev
  108.  
  109.     _split_longopt && split=true
  110.  
  111.     case $prev in
  112.         -h|--host)
  113.             _known_hosts_real "$cur"
  114.             return 0
  115.             ;;
  116.         -U|--username)
  117.             _pg_users
  118.             return 0
  119.             ;;
  120.         -d|--dbname)
  121.             _pg_databases
  122.             return 0
  123.             ;;
  124.         -o|--output|-f|--file|-L|--log-file)
  125.             _filedir
  126.             return 0
  127.             ;;
  128.         -c|--command|-F|--field-separator|-p|--port|-P|--pset|\
  129.         -R|--record-separator|-T|--table-attr|-v|--set|--variable)
  130.             # argument required but no completions available
  131.             return 0
  132.             ;;
  133.         -\?|--help|-V|--version)
  134.             # all other arguments are noop with these
  135.             return 0
  136.             ;;
  137.     esac
  138.  
  139.     $split && return 0
  140.  
  141.     if [[ "$cur" == -* ]]; then
  142.         # return list of available options
  143.         COMPREPLY=( $( compgen -W '--echo-all --no-align --command --dbname \
  144.             --echo-queries --echo-hidden --file --field-separator --host \
  145.             --html --list --log-file --output --port --pset --quiet \
  146.             --record-separator --single-step --single-line --tuples-only \
  147.             --table-attr --username --set --version --password --expanded \
  148.             --no-psqlrc --single-transaction --help' -- "$cur" ) )
  149.     else
  150.         # return list of available databases
  151.         _pg_databases
  152.     fi
  153. }
  154. complete -F _psql -o filenames psql
  155. }
  156.  
  157. # Local variables:
  158. # mode: shell-script
  159. # sh-basic-offset: 4
  160. # sh-indent-comment: t
  161. # indent-tabs-mode: nil
  162. # End:
  163. # ex: ts=4 sw=4 et filetype=sh
  164.