summaryrefslogtreecommitdiffstats
path: root/completions/mysql
diff options
context:
space:
mode:
Diffstat (limited to 'completions/mysql')
-rw-r--r--completions/mysql80
1 files changed, 45 insertions, 35 deletions
diff --git a/completions/mysql b/completions/mysql
index 9363133..4ba049f 100644
--- a/completions/mysql
+++ b/completions/mysql
@@ -1,83 +1,94 @@
# mysql(1) completion -*- shell-script -*-
-_mysql_character_sets()
+# @since 2.12
+_comp_xfunc_mysql_compgen_character_sets()
{
- local IFS=$' \t\n' reset=$(shopt -p failglob)
- shopt -u failglob
- local -a charsets=(/usr/share/m{ariadb,ysql}/charsets/*.xml)
- $reset
+ local -a charsets
+ _comp_expand_glob charsets '/usr/share/m{ariadb,ysql}/charsets/!(Index).xml'
+ charsets+=(utf8)
charsets=("${charsets[@]##*/}")
- charsets=("${charsets[@]%%?(Index|\*).xml}" utf8)
- COMPREPLY+=($(compgen -W '${charsets[@]}' -- "$cur"))
+ charsets=("${charsets[@]%.xml}")
+ _comp_compgen -U charsets -- -W '"${charsets[@]}"' -X ''
}
-_mysql()
+# @deprecated 2.12
+_mysql_character_sets()
{
- local cur prev words cword split
- _init_completion -s || return
+ _comp_compgen -ax mysql character_sets "$@"
+}
+_comp_cmd_mysql()
+{
+ local cur prev words cword was_split comp_args
+ _comp_initialize -s -- "$@" || return
+
+ # Prefer `mysqlshow` in the same dir as the command
+ local pathcmd
+ pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
+
+ local noargopts='!(-*|*[uDhSPeI]*)'
+ # shellcheck disable=SC2254
case $prev in
- --user | -!(-*)u)
- COMPREPLY=($(compgen -u -- "$cur"))
+ --user | -${noargopts}u)
+ _comp_compgen -- -u
return
;;
- --database | -!(-*)D)
- COMPREPLY=($(compgen -W "$(mysqlshow 2>/dev/null | command sed -ne '2d' -e 's/^|.\([^|]*\)|.*/\1/p')" -- "$cur"))
+ --database | -${noargopts}D)
+ _comp_compgen_split -- "$(mysqlshow 2>/dev/null |
+ command sed -ne '2d' -e 's/^|.\([^|]*\)|.*/\1/p')"
return
;;
- --host | -!(-*)h)
- _known_hosts_real -- "$cur"
+ --host | -${noargopts}h)
+ _comp_compgen_known_hosts -- "$cur"
return
;;
--default-character-set)
- _mysql_character_sets
+ _comp_xfunc_mysql_compgen_character_sets
return
;;
--character-sets-dir | --ssl-capath)
- _filedir -d
+ _comp_compgen_filedir -d
return
;;
- --socket | -!(-*)S)
- _filedir sock
+ --socket | -${noargopts}S)
+ _comp_compgen_filedir sock
return
;;
--protocol)
- COMPREPLY=($(compgen -W 'tcp socket pipe memory' -- "$cur"))
+ _comp_compgen -- -W 'tcp socket pipe memory'
return
;;
--defaults-file | --defaults-extra-file | --tee)
- _filedir
+ _comp_compgen_filedir
return
;;
--ssl-ca | --ssl-cert)
- _filedir '@(pem|cer|c?(e)rt)'
+ _comp_compgen_filedir '@(pem|cer|c?(e)rt)'
return
;;
--ssl-key)
- _filedir '@(pem|key)'
+ _comp_compgen_filedir '@(pem|key)'
return
;;
--port | --set-variable | --ssl-cipher | --connect_timeout | \
--max_allowed_packet | --prompt | --net_buffer_length | --select_limit | \
--max_join_size | --server-arg | --debug | --delimiter | --execute | --pager | \
- -!(-*)[Pe])
+ -${noargopts}[Pe])
return
;;
- --help | --version | -!(-*)[?IV])
+ --help | --version | -${noargopts}[?IV])
return
;;
esac
- $split && return
+ [[ $was_split ]] && return
case $cur in
--*)
- local help=$(_parse_help "$1")
- help+=" --skip-comments --skip-ssl"
-
- COMPREPLY=($(compgen -W "$help" -- "$cur"))
+ _comp_compgen_help
+ _comp_compgen -a -- -W '--skip-comments --skip-ssl'
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace
return
;;
@@ -90,10 +101,9 @@ _mysql()
;;
esac
- COMPREPLY=($(compgen -W \
- "$(mysqlshow 2>/dev/null | command sed -ne '2d' -e 's/^|.\([^|]*\)|.*/\1/p')" \
- -- "$cur"))
+ _comp_compgen_split -- "$(mysqlshow 2>/dev/null |
+ command sed -ne '2d' -e 's/^|.\([^|]*\)|.*/\1/p')"
} &&
- complete -F _mysql mysql
+ complete -F _comp_cmd_mysql mysql
# ex: filetype=sh