Improve psql completions and add some related commands (#6620)

This commit is contained in:
Jan Verbeek 2020-02-28 11:16:41 +01:00 committed by GitHub
parent c0271a71d1
commit d02736c0ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 235 additions and 60 deletions

View File

@ -21,6 +21,7 @@
#### Completions #### Completions
- Added completions for - Added completions for
- `wireshark`, `tshark`, and `dumpcap` - `wireshark`, `tshark`, and `dumpcap`
- `dropdb`, `createdb`, `pg_restore`, `pg_dump` and `pg_dumpall`
### Deprecations and removed features ### Deprecations and removed features

View File

@ -0,0 +1,21 @@
complete -c createdb --no-files -a '(__fish_complete_pg_database)'
# Options:
complete -c createdb -s D -l tablespace -x -d "Default tablespace for the database"
complete -c createdb -s e -l echo -d "Show the commands being sent to the server"
complete -c createdb -s E -l encoding -x -d "Encoding for the database"
complete -c createdb -s l -l locale -x -d "Locale settings for the database"
complete -c createdb -l lc-collate -x -d "LC_COLLATE setting for the database"
complete -c createdb -l lc-ctype -x -d "LC_CTYPE setting for the database"
complete -c createdb -s O -l owner -x -a '(__fish_complete_pg_user)' -d "Database user to own the new database"
complete -c createdb -s T -l template -x -a '(__fish_complete_pg_database)' -d "Template database to copy"
complete -c createdb -s V -l version -d "Output version information, then exit"
complete -c createdb -s '?' -l help -d "Show help, then exit"
# Connection options:
complete -c createdb -s h -l host -x -a '(__fish_print_hostnames)' -d "Database server host or socket directory"
complete -c createdb -s p -l port -x -d "Database server port"
complete -c createdb -s U -l username -x -a '(__fish_complete_pg_user)' -d "User name to connect as"
complete -c createdb -s w -l no-password -d "Never prompt for password"
complete -c createdb -s W -l password -d "Force password prompt"
complete -c createdb -l maintenance-db -x -a '(__fish_complete_pg_database)' -d "Alternate maintenance database"

View File

@ -0,0 +1,16 @@
complete -c dropdb --no-files -a '(__fish_complete_pg_database)'
# Options:
complete -c dropdb -s e -l echo -d "Show the commands being sent to the server"
complete -c dropdb -s i -l interactive -d "Prompt before deleting anything"
complete -c dropdb -s V -l version -d "Output version information, then exit"
complete -c dropdb -l if-exists -d "Don't report error if database doesn't exist"
complete -c dropdb -s '?' -l help -d "Show help, then exit"
# Connection options:
complete -c dropdb -s h -l host -x -a '(__fish_print_hostnames)' -d "Database server host or socket directory"
complete -c dropdb -s p -l port -x -d "Database server port"
complete -c dropdb -s U -l username -x -a '(__fish_complete_pg_user)' -d "User name to connect as"
complete -c dropdb -s w -l no-password -d "Never prompt for password"
complete -c dropdb -s W -l password -d "Force password prompt"
complete -c dropdb -l maintenance-db -x -a '(__fish_complete_pg_database)' -d "Alternate maintenance database"

View File

@ -0,0 +1,60 @@
complete -c pg_dump --no-files -a '(__fish_complete_pg_database)'
# General options:
complete -c pg_dump -s f -l file -r -d "Output file or directory name"
complete -c pg_dump -s F -l format -x -a "p\t'Plain text' c\t'Custom format' d\t'Directory archive' t\t'Tar archive'" -d "Output file format"
complete -c pg_dump -s j -l jobs -x -d "Use this many parallel jobs to dump"
complete -c pg_dump -s v -l verbose -d "Verbose mode"
complete -c pg_dump -s V -l version -d "Output version information, then exit"
complete -c pg_dump -s Z -l compress -x -d "Compression level for compressed formats"
complete -c pg_dump -l lock-wait-timeout -x -d "Fail after waiting TIMEOUT for a table lock"
complete -c pg_dump -l no-sync -d "Do not wait for changes to be written safely to disk"
complete -c pg_dump -s '?' -l help -d "Show this help, then exit"
# Options controlling the output content:
complete -c pg_dump -s a -l data-only -d "Dump only the data, not the schema"
complete -c pg_dump -s b -l blobs -d "Include large objects in dump"
complete -c pg_dump -s B -l no-blobs -d "Exclude large objects in dump"
complete -c pg_dump -s c -l clean -d "Clean (drop) database objects before recreating"
complete -c pg_dump -s C -l create -d "Include commands to create database in dump"
complete -c pg_dump -s E -l encoding -x -d "Dump the data in encoding ENCODING"
complete -c pg_dump -s n -l schema -x -d "Dump the named schemas only"
complete -c pg_dump -s N -l exclude-schema -x -d "Do NOT dump the named schemas"
complete -c pg_dump -s o -l oids -d "Include OIDs in dump"
complete -c pg_dump -s O -l no-owner -d "Skip restoration of object ownership in plain-text format"
complete -c pg_dump -s s -l schema-only -d "Dump only the schema, no data"
complete -c pg_dump -s S -l superuser -x -d "Superuser user name to use in plain-text format"
complete -c pg_dump -s t -l table -x -d "Dump the named tables only"
complete -c pg_dump -s T -l exclude-table -x -d "Do NOT dump the named tables"
complete -c pg_dump -s x -l no-privileges -d "Do not dump privileges (grant/revoke)"
complete -c pg_dump -l binary-upgrade -d "For use by upgrade utilities only"
complete -c pg_dump -l column-inserts -d "Dump data as INSERT commands with column names"
complete -c pg_dump -l disable-dollar-quoting -d "Disable dollar quoting, use SQL standard quoting"
complete -c pg_dump -l disable-triggers -d "Disable triggers during data-only restore"
complete -c pg_dump -l enable-row-security -d "Enable row security (dump only content user has access to)"
complete -c pg_dump -l exclude-table-data -x -d "Do NOT dump data for the named tables"
complete -c pg_dump -l if-exists -d "Use IF EXISTS when dropping objects"
complete -c pg_dump -l inserts -d "Dump data as INSERT commands, rather than COPY"
complete -c pg_dump -l load-via-partition-root -d "Load partitions via the root table"
complete -c pg_dump -l no-comments -d "Do not dump comments"
complete -c pg_dump -l no-publications -d "Do not dump publications"
complete -c pg_dump -l no-security-labels -d "Do not dump security label assignments"
complete -c pg_dump -l no-subscriptions -d "Do not dump subscriptions"
complete -c pg_dump -l no-synchronized-snapshots -d "Do not use synchronized snapshots in parallel jobs"
complete -c pg_dump -l no-tablespaces -d "Do not dump tablespace assignments"
complete -c pg_dump -l no-unlogged-table-data -d "Do not dump unlogged table data"
complete -c pg_dump -l quote-all-identifiers -d "Quote all identifiers, even if not key words"
complete -c pg_dump -l section -x -a "pre-data data post-data" -d "Dump named section (pre-data, data, or post-data)"
complete -c pg_dump -l serializable-deferrable -d "Wait until the dump can run without anomalies"
complete -c pg_dump -l snapshot -x -d "Use given snapshot for the dump"
complete -c pg_dump -l strict-names -d "Require table and/or schema include patterns to match at least one entity each"
complete -c pg_dump -l use-set-session-authorization -d "Use SET SESSION AUTHORIZATION commands instead of ALTER OWNER commands to set ownership"
# Connection options:
complete -c pg_dump -s d -l dbname -x -a '(__fish_complete_pg_database)' -d "Database to dump"
complete -c pg_dump -s h -l host -x -a '(__fish_print_hostnames)' -d "Database server host or socket directory"
complete -c pg_dump -s p -l port -x -d "Database server port number"
complete -c pg_dump -s U -l username -x -a '(__fish_complete_pg_user)' -d "Connect as specified database user"
complete -c pg_dump -s w -l no-password -d "Never prompt for password"
complete -c pg_dump -s W -l password -d "Force password prompt (should happen automatically)"
complete -c pg_dump -l role -x -d "Do SET ROLE before dump"

View File

@ -0,0 +1,48 @@
complete -c pg_dumpall --no-files
# General options:
complete -c pg_dumpall -s f -l file -r -d "Output file name"
complete -c pg_dumpall -s v -l verbose -d "Verbose mode"
complete -c pg_dumpall -s V -l version -d "Output version information, then exit"
complete -c pg_dumpall -l lock-wait-timeout -x -d "Fail after waiting TIMEOUT for a table lock"
complete -c pg_dumpall -s '?' -l help -d "Show this help, then exit"
# Options controlling the output content:
complete -c pg_dumpall -s a -l data-only -d "Dump only the data, not the schema"
complete -c pg_dumpall -s c -l clean -d "Clean (drop) database objects before recreating"
complete -c pg_dumpall -s E -l encoding -x -d "Dump the data in encoding ENCODING"
complete -c pg_dumpall -s g -l globals-only -d "Dump only global objects, no databases"
complete -c pg_dumpall -s o -l oids -d "Include OIDs in dump"
complete -c pg_dumpall -s O -l no-owner -d "Skip restoration of object ownership"
complete -c pg_dumpall -s r -l roles-only -d "Dump only roles, no databases or tablespaces"
complete -c pg_dumpall -s s -l schema-only -d "Dump only the schema, no data"
complete -c pg_dumpall -s S -l superuser -x -d "Superuser user name to use in the dump"
complete -c pg_dumpall -s t -l tablespaces-only -d "Dump only tablespaces, no databases or roles"
complete -c pg_dumpall -s x -l no-privileges -d "Do not dump privileges (grant/revoke)"
complete -c pg_dumpall -l binary-upgrade -d "For use by upgrade utilities only"
complete -c pg_dumpall -l column-inserts -d "Dump data as INSERT commands with column names"
complete -c pg_dumpall -l disable-dollar-quoting -d "Disable dollar quoting, use SQL standard quoting"
complete -c pg_dumpall -l disable-triggers -d "Disable triggers during data-only restore"
complete -c pg_dumpall -l if-exists -d "Use IF EXISTS when dropping objects"
complete -c pg_dumpall -l inserts -d "Dump data as INSERT commands, rather than COPY"
complete -c pg_dumpall -l load-via-partition-root -d "Load partitions via the root table"
complete -c pg_dumpall -l no-comments -d "Do not dump comments"
complete -c pg_dumpall -l no-publications -d "Do not dump publications"
complete -c pg_dumpall -l no-role-passwords -d "Do not dump passwords for roles"
complete -c pg_dumpall -l no-security-labels -d "Do not dump security label assignments"
complete -c pg_dumpall -l no-subscriptions -d "Do not dump subscriptions"
complete -c pg_dumpall -l no-sync -d "Do not wait for changes to be written safely to disk"
complete -c pg_dumpall -l no-tablespaces -d "Do not dump tablespace assignments"
complete -c pg_dumpall -l no-unlogged-table-data -d "Do not dump unlogged table data"
complete -c pg_dumpall -l quote-all-identifiers -d "Quote all identifiers, even if not key words"
complete -c pg_dumpall -l use-set-session-authorization -d "Use SET SESSION AUTHORIZATION commands instead of ALTER OWNER commands to set ownership"
# Connection options:
complete -c pg_dumpall -s d -l dbname -x -a '(__fish_complete_pg_database)' -d "Database to dump"
complete -c pg_dumpall -s h -l host -x -a '(__fish_print_hostnames)' -d "Database server host or socket directory"
complete -c pg_dumpall -s l -l database -x -a '(__fish_complete_pg_database)' -d "Alternative default database"
complete -c pg_dumpall -s p -l port -x -d "Database server port number"
complete -c pg_dumpall -s U -l username -x -a '(__fish_complete_pg_user)' -d "Connect as specified database user"
complete -c pg_dumpall -s w -l no-password -d "Never prompt for password"
complete -c pg_dumpall -s W -l password -d "Force password prompt (should happen automatically)"
complete -c pg_dumpall -l role -x -d "Do SET ROLE before dump"

View File

@ -0,0 +1,47 @@
# General options:
complete -c pg_restore -s d -l dbname -x -a '(__fish_complete_pg_database)' -d "Connect to database name"
complete -c pg_restore -s f -l file -a '-' -r -d "Output file name (- for stdout)"
complete -c pg_restore -s F -l format -x -a "c\t'Custom format (pg_dump)' d\t'Directory archive' t\t'Tar archive'" -d "Backup file format (should be automatic)"
complete -c pg_restore -s l -l list -d "Print summarized TOC of the archive"
complete -c pg_restore -s v -l verbose -d "Verbose mode"
complete -c pg_restore -s V -l version -d "Output version information, then exit"
complete -c pg_restore -s '?' -l help -d "Show help, then exit"
# Options controlling the restore:
complete -c pg_restore -s a -l data-only -d "Restore only the data, no schema"
complete -c pg_restore -s c -l clean -d "Clean (drop) database objects before recreating"
complete -c pg_restore -s C -l create -d "Create the target database"
complete -c pg_restore -s e -l exit-on-error -d "Exit on error, default is to continue"
complete -c pg_restore -s I -l index -x -d "Restore named index"
complete -c pg_restore -s j -l jobs -x -d "Use this many parallel jobs to restore"
complete -c pg_restore -s L -l use-list -r -d "Use table of contents from this file for selecting/ordering output"
complete -c pg_restore -s n -l schema -x -d "Restore only objects in this schema"
complete -c pg_restore -s N -l exclude-schema -x -d "Do not restore objects in this schema"
complete -c pg_restore -s O -l no-owner -d "Skip restoration of object ownership"
complete -c pg_restore -s P -l function -x -d "Restore named function"
complete -c pg_restore -s s -l schema-only -d "Restore only the schema, no data"
complete -c pg_restore -s S -l superuser -x -a '(__fish_complete_pg_user)' -d "Superuser user name to use for disabling triggers"
complete -c pg_restore -s t -l table -x -d "Restore named relation (table, view, etc.)"
complete -c pg_restore -s T -l trigger -x -d "Restore named trigger"
complete -c pg_restore -s x -l no-privileges -d "Skip restoration of access privileges (grant/revoke)"
complete -c pg_restore -s 1 -l single-transaction -d "Restore as a single transaction"
complete -c pg_restore -l disable-triggers -d "Disable triggers during data-only restore"
complete -c pg_restore -l enable-row-security -d "Enable row security"
complete -c pg_restore -l if-exists -d "Use IF EXISTS when dropping objects"
complete -c pg_restore -l no-comments -d "Do not restore comments"
complete -c pg_restore -l no-data-for-failed-tables -d "Do not restore data of tables that could not be created"
complete -c pg_restore -l no-publications -d "Do not restore publications"
complete -c pg_restore -l no-security-labels -d "Do not restore security labels"
complete -c pg_restore -l no-subscriptions -d "Do not restore subscriptions"
complete -c pg_restore -l no-tablespaces -d "Do not restore tablespace assignments"
complete -c pg_restore -l section -x -d "Restore named section (pre-data, data, or post-data)"
complete -c pg_restore -l strict-names -d "Require table and/or schema include patterns to match at least one entity each"
complete -c pg_restore -l use-set-session-authorization -d "Use SET SESSION AUTHORIZATION commands instead of ALTER OWNER commands to set ownership"
# Connection options:
complete -c pg_restore -s h -l host -x -a '(__fish_print_hostnames)' -d "Database server host or socket directory"
complete -c pg_restore -s p -l port -x -d "Database server port number"
complete -c pg_restore -s U -l username -x -a '(__fish_complete_pg_user)' -d "Connect as specified database user"
complete -c pg_restore -s w -l no-password -d "Never prompt for password"
complete -c pg_restore -s W -l password -d "Force password prompt (should happen automatically)"
complete -c pg_restore -l role -x -d "Do SET ROLE before restore"

View File

@ -1,66 +1,42 @@
function __fish_complete_pg_database
psql -AtqwlF \t 2>/dev/null | awk 'NF > 1 { print $1 }'
end
function __fish_complete_pg_user
psql -Atqwc 'select usename from pg_user' template1 2>/dev/null
end
complete -c psql --no-files -a '(__fish_complete_pg_database)' complete -c psql --no-files -a '(__fish_complete_pg_database)'
#
# General options: # General options:
# complete -c psql -s d -l dbname -x -a '(__fish_complete_pg_database)' -d "Database name to connect to"
complete -c psql -s c -l command -d "Run only single command (SQL or internal) and exit"
complete -c psql -s f -l file -r -d "Execute commands from file, then exit"
complete -c psql -s l -l list -d "List available databases, then exit"
complete -c psql -s v -l set -l variable -x -d "Set psql variable NAME to VALUE"
complete -c psql -s X -l no-psqlrc -d "Do not read startup file (~/.psqlrc)"
complete -c psql -s 1 -l single-transaction -d "Execute command file as a single transaction"
complete -c psql -s '?' -l help -a "options commands variables" -d "Show this help, then exit"
complete -c psql -l version -d "Output version information, then exit"
complete -c psql -s d -l dbname -a '(__fish_complete_pg_database)' -d "database name to connect to" # Input and output options:
complete -c psql -s c -l command -d "run only single command (SQL or internal) and exit" complete -c psql -s a -l echo-all -d "Echo all input from script"
complete -c psql -s f -l file -r -d "execute commands from file, then exit" complete -c psql -s b -l echo-errors -d "Echo failed commands"
complete -c psql -s l -l list -d "list available databases, then exit" complete -c psql -s e -l echo-queries -d "Echo commands sent to server"
complete -c psql -s E -l echo-hidden -d "Display queries that internal commands generate"
complete -c psql -s L -l log-file -r -d "Send session log to file"
complete -c psql -s n -l no-readline -d "Disable enhanced command line editing (readline)"
complete -c psql -s o -l output -r -d "Send query results to file (or |pipe)"
complete -c psql -s q -l quiet -d "Run quietly (no messages, only query output)"
complete -c psql -s s -l single-step -d "Single-step mode (confirm each query)"
complete -c psql -s S -l single-line -d "Single-line mode (end of line terminates SQL command)"
# complete -c psql -s v -l set=, --variable=NAME=VALUE # Output format options:
# set psql variable NAME to VALUE complete -c psql -s A -l no-align -d "Unaligned table output mode"
complete -c psql -s H -l html -d "HTML table output mode"
complete -c psql -s P -l pset -d "Set printing option VAR to ARG (see \pset command)"
complete -c psql -s t -l tuples-only -d "Print rows only"
complete -c psql -s T -l table-attr -d "Set HTML table tag attributes (e.g., width, border)"
complete -c psql -s x -l expanded -d "Turn on expanded table output"
complete -c psql -s F -l field-separator -x -d "Set field separator (default: '|')"
complete -c psql -s R -l record-separator -x -d "Set record separator (default: newline)"
complete -c psql -s 0 -l record-separator-zero -d "Set record separator for unaligned output to zero byte"
complete -c psql -s X -l no-psqlrc -d "do not read startup file (~/.psqlrc)" # Connection options:
complete -c psql -s 1 -l single-transaction -d "execute command file as a single transaction" complete -c psql -s h -l host -x -a '(__fish_print_hostnames)' -d "Database server host or socket directory"
complete -c psql -l help -d "show this help, then exit" complete -c psql -s p -l port -x -d "Database server port"
complete -c psql -l version -d "output version information, then exit" complete -c psql -s U -l username -x -a '(__fish_complete_pg_user)' -d "Database user name"
complete -c psql -s w -l no-password -d "Never prompt for password"
# complete -c psql -s W -l password -d "Force password prompt (should happen automatically)"
# Input and output options:
#
complete -c psql -s a, -l echo-all -d "echo all input from script"
complete -c psql -s e, -l echo-queries -d "echo commands sent to server"
complete -c psql -s E, -l echo-hidden -d "display queries that internal commands generate"
complete -c psql -s L, -l log-file -d "send session log to file"
complete -c psql -s n, -l no-readline -d "disable enhanced command line editing (readline)"
complete -c psql -s o, -l output -d "send query results to file (or |pipe)"
complete -c psql -s q, -l quiet -d "run quietly (no messages, only query output)"
complete -c psql -s s, -l single-step -d "single-step mode (confirm each query)"
complete -c psql -s S, -l single-line -d "single-line mode (end of line terminates SQL command)"
#
# Output format options:
#
complete -c psql -s A, -l no-align -d "unaligned table output mode"
complete -c psql -s H, -l html -d "HTML table output mode"
complete -c psql -s P, -l pset -d "set printing option VAR to ARG (see \pset command)"
complete -c psql -s t, -l tuples-only -d "print rows only"
complete -c psql -s T, -l table-attr -d "set HTML table tag attributes (e.g., width, border)"
complete -c psql -s x, -l expanded -d "turn on expanded table output"
complete -c psql -s F, -l field-separator -d "set field separator (default: '|')"
complete -c psql -s R, -l record-separator -d "set record separator (default: newline)"
#
# Connection options
#
complete -c psql -s h -l host -a '(__fish_print_hostnames)' -d "database server host or socket directory"
complete -c psql -s p -l port -x -d "database server port"
complete -c psql -s U -l username -a '(__fish_complete_pg_user)' -d "database user name"
complete -c psql -s w -l no-password -d "never prompt for password"
complete -c psql -s W -l password -d "force password prompt (should happen automatically)"

View File

@ -0,0 +1,3 @@
function __fish_complete_pg_database
psql -AtqwlF \t 2>/dev/null | awk 'NF > 1 { print $1 }'
end

View File

@ -0,0 +1,3 @@
function __fish_complete_pg_user
psql -Atqwc 'select usename from pg_user' template1 2>/dev/null
end