zsh-workers
 help / color / mirror / code / Atom feed
* Re: PATCH: mysql completions
@ 2000-03-13 10:29 Sven Wischnowsky
  2000-07-31 22:14 ` missing -o kshautoload checks Adam Spiers
  0 siblings, 1 reply; 4+ messages in thread
From: Sven Wischnowsky @ 2000-03-13 10:29 UTC (permalink / raw)
  To: zsh-workers


Adam Spiers wrote:

> This turned out to be a really good way of getting my head round
> recent changes to the completion system.  Comments on the style (and
> correctness, especially relating to tags) welcome ...

The tags stuff looks fine, as far as I can see.

> ...
> 
> +_mysql_databases () {
> +  local _mysql_user _mysql_port _mysql_host _mysql_params
> +  _mysql_get_identity
> +
> +  local _mysql_databases
> +  _mysql_databases=(
> +                    ${(f)~~"$( echo "show databases" |
> +                               mysql "$_mysql_params[@]" )"}
> +                   )
> +  shift _mysql_databases
> +
> +  compadd "$expl[@]" - $_mysql_databases
> +}

This works, because $expl is set in all callers, but I think it would
be nicer to make this explicit by using $@. _argument gives $expl as
the arguments anyway (the way _mysql_databases is called from it) and
for the call from _*_commands it could easily be added. Maybe that's
just personal taste.

> +_mysql_tables () {
> +  local _mysql_user _mysql_port _mysql_host _mysql_params
> +  _mysql_get_identity
> +
> +  local _mysql_tables
> +  _mysql_tables=(
> +                 ${(f)~~"$( echo "show tables" |
> +                              mysql "$_mysql_params[@]" $1 )"}
> +                )
> +  # remove header
> +  shift _mysql_tables
> +
> +  compadd "$expl[@]" - $_mysql_tables
> +}

Almost the same, I think it would be better to change the calls to use 
`{ _mysql_tables $line[1] $expl }'.

> ...
>
> +_mysql_utils "$@"

[[ -o kshautoload ]] || _mysql_utils "$@"

(I hate kshautoload, too ;-)

Bye
 Sven


--
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


^ permalink raw reply	[flat|nested] 4+ messages in thread

* missing -o kshautoload checks
  2000-03-13 10:29 PATCH: mysql completions Sven Wischnowsky
@ 2000-07-31 22:14 ` Adam Spiers
  2000-08-01  7:12   ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Adam Spiers @ 2000-07-31 22:14 UTC (permalink / raw)
  To: zsh-workers

A while ago, Sven Wischnowsky (wischnow@informatik.hu-berlin.de) wrote:
> [[ -o kshautoload ]] || _mysql_utils "$@"
> 
> (I hate kshautoload, too ;-)

A recursive grep for '_[a-z_]* "$@"' in the Completion directory
reveals that there are quite a few of these [[ -o kshautoload ]]
checks missing.  I'm a bit short on time right now; any kind soul care
to add them in?


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: missing -o kshautoload checks
  2000-07-31 22:14 ` missing -o kshautoload checks Adam Spiers
@ 2000-08-01  7:12   ` Bart Schaefer
  0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2000-08-01  7:12 UTC (permalink / raw)
  To: Adam Spiers, zsh-workers

On Jul 31, 11:14pm, Adam Spiers wrote:
} 
} A recursive grep for '_[a-z_]* "$@"' in the Completion directory
} reveals that there are quite a few of these [[ -o kshautoload ]]
} checks missing.  I'm a bit short on time right now; any kind soul care
} to add them in?

I think there was at least a semi-conscious decision to stop including
those lines.  Chapter "Completion System" section "Initialization" heading
"Autoloaded files" explains:

  Note also that the functions for the completion system assume that the
  KSH_AUTOLOAD option is not set and cannot be loaded when it is set.  To
  avoid having to unset KSH_AUTOLOAD, you can instead use one or more zwc
  file which have been created with the command zcompile -z to load
  the functions for the completion system; see *Note Shell Builtin
  Commands::.  This forces the functions to be autoloaded the way zsh
  normally loads functions.

I haven't actually tried it, but I'm pretty sure that if you `zcompile -z'
a file that ends with `[[ -o kshautoload ]] && $0 "$@"', and you have
kshautoload set, you'll end up executing the function *twice* the first
time it's autoloaded.  So really we should be *removing* all the checks
for kshautoload, not adding more of them.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


^ permalink raw reply	[flat|nested] 4+ messages in thread

* PATCH: mysql completions
@ 2000-03-11 18:25 Adam Spiers
  0 siblings, 0 replies; 4+ messages in thread
From: Adam Spiers @ 2000-03-11 18:25 UTC (permalink / raw)
  To: zsh workers mailing list

This turned out to be a really good way of getting my head round
recent changes to the completion system.  Comments on the style (and
correctness, especially relating to tags) welcome ...

I haven't included a patch for Completion/User/.distfiles, as I'm
quite out of sync and it might have broken.

Index: Completion/User/_mysql_utils
=================================================================== 
--- Completion/User/_mysql_utils	Sat Mar 11 18:18:50 2000
+++ Completion/User/_mysql_utils	Sat Mar 11 18:18:25 2000
@@ -0,0 +1,245 @@
+#compdef mysql mysqlshow mysqldump mysqladmin
+#
+# zsh completion functions for mysql client programs
+# Adam Spiers <adam@spiers.net>
+#
+
+##
+## Auxiliary functions
+##
+
+_mysql_get_identity () {
+  _mysql_user=${opt_args[-u]-$opt_args[--user]}
+  _mysql_port=${opt_args[-P]-$opt_args[--port]}
+  _mysql_host=${opt_args[-h]-$opt_args[--host]}
+
+  _mysql_params=(
+                 ${_mysql_user+"--user=$_mysql_user"}
+                 ${_mysql_host+"--host=$_mysql_host"}
+                 ${_mysql_port+"--port=$_mysql_port"}
+                )
+}
+
+_mysql_hosts () {
+  local _mysql_user _mysql_port _mysql_host _mysql_params
+  _mysql_get_identity
+
+  _wanted hosts expl 'server host' &&
+    _combination -s '[:@]' '' hosts-ports-users \
+      ${_mysql_user:+users=${_mysql_user:q}} \
+      ${_mysql_port:+ports=${_mysql_port:q}} \
+      hosts "$expl[@]"
+}
+
+_mysql_ports () {
+  local _mysql_user _mysql_port _mysql_host _mysql_params
+  _mysql_get_identity
+
+  _wanted ports expl 'server port' &&
+    _combination -s '[:@]' '' hosts-ports-users \
+      ${_mysql_user:+users=${_mysql_user:q}} \
+      ${_mysql_host:+hosts=${_mysql_host:q}} \
+      ports "$expl[@]"
+}
+
+_mysql_users () {
+  local _mysql_user _mysql_port _mysql_host _mysql_params
+  _mysql_get_identity
+
+  _wanted users expl 'server username' &&
+    _combination -s '[:@]' '' hosts-ports-users \
+      ${_mysql_host:+hosts=${_mysql_host:q}} \
+      ${_mysql_port:+ports=${_mysql_port:q}} \
+      users "$expl[@]"
+}
+
+_mysql_databases () {
+  local _mysql_user _mysql_port _mysql_host _mysql_params
+  _mysql_get_identity
+
+  local _mysql_databases
+  _mysql_databases=(
+                    ${(f)~~"$( echo "show databases" |
+                               mysql "$_mysql_params[@]" )"}
+                   )
+  shift _mysql_databases
+
+  compadd "$expl[@]" - $_mysql_databases
+}
+
+_mysql_tables () {
+  local _mysql_user _mysql_port _mysql_host _mysql_params
+  _mysql_get_identity
+
+  local _mysql_tables
+  _mysql_tables=(
+                 ${(f)~~"$( echo "show tables" |
+                              mysql "$_mysql_params[@]" $1 )"}
+                )
+  # remove header
+  shift _mysql_tables
+
+  compadd "$expl[@]" - $_mysql_tables
+}
+
+_mysql_variables () {
+  _values -s , 'MySQL client variables' \
+    'max_allowed_packet[maximum allowed packet size]:Packet size in bytes:' \
+    'net_buffer_length[network buffer length]:Buffer length in bytes:'
+}
+
+
+##
+## The actual completion code for the commands
+##
+
+_mysql_common_opts=(
+    {-\?,--help}'[display help]'
+    {-S+,--socket=}':server socket file:_files'
+    {-h+,--host=}':server hostname:_mysql_hosts'
+    {-P+,--port=}':server port:_mysql_ports'
+    {-u+,--user=}':server username:_mysql_users'
+    {-p+,--password=}':server password: '
+    {-C,--compress}'[use compression in server/client protocol]'
+)
+
+_mysql () {
+  local curcontext="$curcontext" state line expl
+  typeset -A opt_args
+
+  _arguments -C -s \
+    "$_mysql_common_opts[@]" \
+    {-V,--version}'[display client version]' \
+    {-A,--no-auto-rehash}'[no automatic rehashing]' \
+    '(-t --table)'{-B,--batch}'[batch mode (no pretty ASCII)]' \
+    {-T,--debug-info}'[print debug info on exit]' \
+    {-e,--exec-command}':batch-execute specified command and exit: ' \
+    {-f,--force}'[continue through errors]' \
+    {-i,--ignore-space}'[ignore space after function names]' \
+    {-H,--html}'[produce HTML output]' \
+    {-n,--unbuffered}'[flush the buffer after each query]' \
+    {-O,--set-variable=}':set variable:_mysql_variables' \
+    {-o,--one-database}'[only update the default database]' \
+    {-q,--quick}'[disable caching of the result]' \
+    {-r,--raw}'[write fields without conversion]' \
+    {-s,--silent}'[silent mode]' \
+    {-L,--skip-line-numbers}"[don't write line number for errors]" \
+    {-N,--skip-column-names}"[don't write column names in results]" \
+    '(-B --batch)'{-t,--table}'[output in table format]' \
+    {-v,--verbose}'[verbose mode]' \
+    {-E,--vertical}'[print query output vertically]' \
+    {-w,--wait}'[wait and retry server connection if necessary]' \
+    ':MySQL database to use:_mysql_databases'
+}
+
+_mysqlshow () {
+  local curcontext="$curcontext" state line expl
+  typeset -A opt_args
+
+  _arguments -C -s \
+    "$_mysql_common_opts[@]" \
+    {-V,--version}'[display version]' \
+    {-\#+,--debug=}':debug file: ' \
+    ':MySQL database to show:_mysql_databases' \
+    ':table to show:{ _mysql_tables "$line[1]" }' \
+    ':field wildcard: '
+}
+
+_mysqldump () {
+  local curcontext="$curcontext" state line expl
+  typeset -A opt_args
+
+  _arguments -C -s \
+    "$_mysql_common_opts[@]" \
+    {-V,--version}'[display version]' \
+    {-a,--all}'[include all create options]' \
+    {-\#+,--debug=}':debug file: ' \
+    {-c,--complete-insert}'[use complete insert statements]' \
+    {-e,--extended-insert}'[allow new INSERT syntax]' \
+    "--add-drop-table[add a 'drop table' before each create]" \
+    "--add-locks[add locks around insert statements]" \
+    "--allow-keywords[allow creation of column names that are keywords]" \
+    "--delayed[insert rows with INSERT DELAYED]" \
+    {-F,--flush-logs}'[flush logs file in server before dump]' \
+    {-l,--lock-tables}'[lock all tables for read]' \
+    {-t,--no-create-info}"[don't write table creation info]" \
+    {-d,--no-data}"[don't write row information]" \
+    {-O,--set-variable}':set variable:_mysql_variables' \
+    '--opt[create fastest possible dump for reading]' \
+    {-q,--quick}"[don't buffer, dump directly to stdout]" \
+    {-T,--tab=}"[dump tab-separated text files for each table]:directory to store text files:_files -/" \
+    {-w+,--where=}'[dump only selected records]:WHERE clause to limit records to dump: ' \
+    '--fields-terminated-by=:(with --tab) fields in textfile terminated by ...: ' \
+    '--fields-enclosed-by=:(with --tab) fields in import file enclosed by ...: ' \
+    '--fields-optionally-enclosed-by=:(with --tab) fields in import file optionally enclosed by ...: ' \
+    '--fields-escaped-by=:(with --tab) fields in import file escaped by ...: ' \
+    '--lines-terminated-by=:(with --tab) lines in import file terminated by ...: ' \
+    ':MySQL database to dump:_mysql_databases' \
+    '*:tables to dump:{ _mysql_tables "$line[1]" }'
+}
+
+_mysqladmin () {
+  local curcontext="$curcontext" state line expl
+  typeset -A opt_args
+
+  _arguments -C -s \
+    "$_mysql_common_opts[@]" \
+    {-v,--version}'[display version]' \
+    {-\#+,--debug=}':debug file: ' \
+    {-f,--force}'[continue through errors]' \
+    {-i+,--sleep=}'[repeat commands periodically]:number of seconds between executions: ' \
+    {-s,--silent}"[silently exit if can't connect to server]" \
+    {-t+,--timeout=}'[timeout for connection]' \
+    {-w+,--wait=}'[wait and retry server connection if necessary]:number of retries: ' \
+    '*::admin command:_mysqladmin_commands'
+}
+
+_mysqladmin_commands () {
+  local cmds expl
+  cmds=(
+        create drop extended-status
+        flush-{hosts,logs,status,tables,privileges}
+        kill password ping processlist
+        reload refresh shutdown
+        status variables version
+       )
+
+  if (( CURRENT == 1 )); then
+    _tags commands && compadd "$@" $cmds
+  else
+    local curcontext="$curcontext"
+
+    case "$words[1]" in
+      (create)
+      ;&
+      (drop)
+        _wanted mysqldbs expl "MySQL databases" && _mysql_databases
+      ;;
+      (kill)
+        _message 'thread ids'
+      ;;
+      (password)
+        _message 'new password'
+      ;;
+    esac
+  fi
+}
+
+_mysql_utils () {
+  case "$words[1]" in
+    mysql)
+      _mysql "$@"
+    ;;
+    mysqlshow)
+      _mysqlshow "$@"
+    ;;
+    mysqldump)
+      _mysqldump "$@"
+    ;;
+    mysqladmin)
+      _mysqladmin "$@"
+    ;;
+  esac
+}
+
+_mysql_utils "$@"


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2000-08-01  7:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-03-13 10:29 PATCH: mysql completions Sven Wischnowsky
2000-07-31 22:14 ` missing -o kshautoload checks Adam Spiers
2000-08-01  7:12   ` Bart Schaefer
  -- strict thread matches above, loose matches on Subject: below --
2000-03-11 18:25 PATCH: mysql completions Adam Spiers

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).