summaryrefslogtreecommitdiff
path: root/contrib/postgresql
diff options
context:
space:
mode:
authorGuillaume Rousse <guillomovitch@zarb.org>2009-05-21 01:21:31 +0200
committerGuillaume Rousse <guillomovitch@zarb.org>2009-05-21 01:21:31 +0200
commit35302e458f28be1629cc773c1d66cc05ee253cbd (patch)
tree11a76e5508f40c1f2bc67762e7fda5d45b658254 /contrib/postgresql
parent4fadb6887aa48cb4b835209a2733010f5f94c3cb (diff)
downloadbash-completion-35302e458f28be1629cc773c1d66cc05ee253cbd.tar.gz
split postgresql completion
Diffstat (limited to 'contrib/postgresql')
-rw-r--r--contrib/postgresql131
1 files changed, 131 insertions, 0 deletions
diff --git a/contrib/postgresql b/contrib/postgresql
new file mode 100644
index 00000000..d0b974eb
--- /dev/null
+++ b/contrib/postgresql
@@ -0,0 +1,131 @@
+# -*- mode: shell-script; sh-basic-offset: 8; indent-tabs-mode: t -*-
+# ex: ts=8 sw=8 noet filetype=sh
+#
+# bash completion for Postgresql
+
+have psql && {
+_pg_databases()
+{
+ return # intentionally disabled in 7ebed6af (TODO: why?)
+ COMPREPLY=( $( compgen -W "$( psql -l 2>/dev/null | \
+ sed -e '1,/^-/d' -e '/^(/,$d' | \
+ awk '{print $1}' )" -- $cur ) )
+}
+
+_pg_users()
+{
+ #COMPREPLY=( $( psql -qtc 'select usename from pg_user' template1 2>/dev/null | \
+ # grep "^ $cur" ) )
+ #[ ${#COMPREPLY[@]} -eq 0 ] && COMPREPLY=( $( compgen -u -- $cur ) )
+ COMPREPLY=( $( compgen -u -- $cur ) )
+}
+
+# createdb(1) completion
+#
+_createdb()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ -@(h|-host=))
+ _known_hosts
+ return 0
+ ;;
+ -@(U|-username=))
+ _pg_users
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-D -T -E -h -p -U -W -e -q \
+ --location= --template= --encoding= --host= --port= \
+ --username= --password --echo --quiet --help' -- $cur ))
+ else
+ _pg_databases
+ fi
+}
+complete -F _createdb $default createdb
+
+# dropdb(1) completion
+#
+_dropdb()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ -@(h|-host=))
+ _known_hosts
+ return 0
+ ;;
+ -@(U|-username=))
+ _pg_users
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ COMPREPLY=( $( compgen -W '-h -p -U -W -e -q \
+ --host= --port= --username= --password \
+ --interactive --echo --quiet --help' -- $cur ) )
+ else
+ _pg_databases
+ fi
+}
+complete -F _dropdb $default dropdb
+
+# psql(1) completion
+#
+_psql()
+{
+ local cur prev
+
+ COMPREPLY=()
+ cur=`_get_cword`
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+
+ case "$prev" in
+ -h|--host)
+ _known_hosts
+ return 0
+ ;;
+ -U|--username)
+ _pg_users
+ return 0
+ ;;
+ -d|--dbname)
+ _pg_databases
+ return 0
+ ;;
+ -@(o|f)|--output|--file)
+ _filedir
+ return 0
+ ;;
+ esac
+
+ if [[ "$cur" == -* ]]; then
+ # return list of available options
+ COMPREPLY=( $( compgen -W '-a --echo-all -A --no-align \
+ -c --command -d --dbname -e --echo-queries \
+ -E --echo-hidden -f --file -F --filed-separator \
+ -h --host -H --html -l --list -n -o --output \
+ -p --port -P --pset -q -R --record-separator \
+ -s --single-step -S --single-line -t --tuples-only \
+ -T --table-attr -U --username -v --variable \
+ -V --version -W --password -x --expanded -X --nopsqlrc \
+ -? --help ' -- $cur ) )
+ else
+ # return list of available databases
+ _pg_databases
+ fi
+}
+complete -F _psql $default psql
+}