Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[PATCH] Add _sqlite for sqlite and sqlite3 completion.



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



Messages sorted by: Reverse Date, Date, Thread, Author