zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] Add _sqlite for sqlite and sqlite3 completion.
@ 2011-03-19 14:11 Benjamin R. Haskell
  2011-03-19 16:11 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Benjamin R. Haskell @ 2011-03-19 14:11 UTC (permalink / raw)
  To: Zsh Workers; +Cc: zsh

This adds a completion function for the SQLite cli tool.

Two questions:

1. Is there an easy way to specify to _arguments that '-opt' and '--opt' should
be treated as equivalent?  SQLite's help specifies its options as '-opt', but
in testing, it accepts either form.  I'd rather not pepper everything with
'{,-}' everywhere there's an option.  (Though I could, if that's preferable.)

2. For the argument specifying a database file, I used:

 "1:database file:_files -g '(#i)*.(db|$service)(-.)'"

So, sqlite (which is the version < 3 tool) only completes files with .db or
.sqlite extensions, and sqlite3 (the version 3 tool) only completes .db or
.sqlite3 files.

Is there a quick way to specify:

Prefer files that match *.$service
If no files match that, try *.db or *.sqlite(|3)
If no files match that, show all files

A lot of things that use SQLite use different extensions (or no extension at
all) on the SQLite files they use.

---
 Completion/Unix/Command/_sqlite |   34 ++++++++++++++++++++++++++++++++++
 1 files changed, 34 insertions(+), 0 deletions(-)
 create mode 100644 Completion/Unix/Command/_sqlite

diff --git a/Completion/Unix/Command/_sqlite b/Completion/Unix/Command/_sqlite
new file mode 100644
index 0000000..11d670b
--- /dev/null
+++ b/Completion/Unix/Command/_sqlite
@@ -0,0 +1,34 @@
+#compdef sqlite sqlite3
+
+_sqlite () {
+  local opt display_opt excludeopts
+  local -a _opts _output_modes
+
+  _opts=(
+    '-init[startup file]:file name to process:_files'
+    '-echo[echo commands]'
+    '(-noheader)-header[turn headers on]'
+    '(-header)-noheader[turn headers off]'
+  )
+
+  # output modes are mutually exclusive to each other
+  _output_modes=( column HTML line list )
+  excludeopts="-${^_output_modes:l}"
+  for display_opt in $_output_modes ; do
+    opt=$display_opt:l
+    # finagle the description to match the way SQLite's help formats them
+    [[ $opt = $display_opt ]] && display_opt="'$display_opt'"
+    _opts+=( "($excludeopts)-${opt}[set output mode to $display_opt]" )
+  done
+
+  _opts+=(
+    '-separator[set output field separator]:string to separate output fields:'
+    '-nullvalue[set null value string]:string for NULL values:'
+    '(- : *)-version[show SQLite version]'
+    '(- : *)-help[show help]'
+    "1:database file:_files -g '(#i)*.(db|$service)(-.)'"
+    '*:SQL to run'
+  )
+
+  _arguments -s $_opts
+}
-- 
1.7.3.1


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

* Re: [PATCH] Add _sqlite for sqlite and sqlite3 completion.
  2011-03-19 14:11 [PATCH] Add _sqlite for sqlite and sqlite3 completion Benjamin R. Haskell
@ 2011-03-19 16:11 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2011-03-19 16:11 UTC (permalink / raw)
  To: Zsh Workers

On Mar 19, 10:11am, Benjamin R. Haskell wrote:
} Subject: [PATCH] Add _sqlite for sqlite and sqlite3 completion.
}
} 1. Is there an easy way to specify to _arguments that '-opt' and
} '--opt' should be treated as equivalent?

No, not really.  Because of the possibility that "-opt" is short for
"-o -p -t", _arguments makes it the job of the caller to distinguish.

} Is there a quick way to specify:
} 
} Prefer files that match *.$service
} If no files match that, try *.db or *.sqlite(|3)
} If no files match that, show all files

That's a job for the file-patterns style.  Don't attempt to figure out
in the _arguments settings what files are suitable; before calling
_arguments, check whether file-patterns is set for the appropriate
context and if it is not then assert a setting for it.  (Or don't,
and make the user do it.)  Then let _files work out the conditional.


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

end of thread, other threads:[~2011-03-19 16:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-19 14:11 [PATCH] Add _sqlite for sqlite and sqlite3 completion Benjamin R. Haskell
2011-03-19 16:11 ` Bart Schaefer

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).