zsh-workers
 help / color / mirror / code / Atom feed
From: "Benjamin R. Haskell" <zsh@benizi.com>
To: Zsh Workers <zsh-workers@zsh.org>
Cc: <zsh@benizi.com>
Subject: [PATCH] Add sqlite and sqlite3 completion.
Date: Sun, 22 Jan 2012 15:24:06 -0500	[thread overview]
Message-ID: <1327263846-5336-1-git-send-email-zsh@benizi.com> (raw)

From: "Benjamin R. Haskell" <zsh@benizi.com>

This adds completion for the sqlite and sqlite3 commands.

I posted the first version of this in workers:28923, asking about limiting the
filenames.  Bart responded in workers:28924 that filename filtering was the job
of the file-patterns style.  Because of that (and because SQLite files often
have no .sqlite-identifying extension), I punted on it: the options that take
filenames (-init, and the positional argument for the SQLite db file) just use
_files.

This version also handles the differences I observed in sqlite/sqlite3 handling
(sqlite3 allows "--option", has --csv as an output format, and has a few more
options).

---
 Completion/Unix/Command/_sqlite |   50 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 50 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..05027c6
--- /dev/null
+++ b/Completion/Unix/Command/_sqlite
@@ -0,0 +1,50 @@
+#compdef sqlite sqlite3
+
+local ret opt display_opt sqlite3
+local -a options output_modes exclusive dashes
+
+[[ $service = sqlite3 ]] && sqlite3=true || unset sqlite3
+
+# sqlite options require a single hyphen, but
+# sqlite3 allows options with one or two
+dashes=( '' )
+(( $+sqlite3 )) && dashes+=( - )
+
+options=(
+  '(-init --init)'$^dashes'-init[startup file]:file containing SQLite commands:_files'
+  $^dashes'-echo[echo commands]'
+)
+
+exclusive=( {,-}-{no,}header )
+options+=(
+  "($exclusive)"$^dashes'-header[turn headers on]'
+  "($exclusive)"$^dashes'-noheader[turn headers off]'
+)
+
+output_modes=( column HTML line list )
+(( $+sqlite3 )) && output_modes+=( csv )
+exclusive=( $^dashes-${^output_modes:l} )
+for display_opt in $output_modes ; do
+  # finagle the description to match the way SQLite's -help formats them
+  opt=$display_opt:l
+  [[ $opt = $display_opt ]] && display_opt="'$display_opt'"
+  options+=( "($exclusive)"$^dashes"-${opt}[set output mode to $display_opt]" )
+done
+
+options+=(
+  $^dashes'-separator[set output field separator]:string to separate output fields:'
+  $^dashes'-nullvalue[set null value string]:string for NULL values:'
+  '(- :)'$^dashes'-version[show SQLite version]'
+  '(- :)'$^dashes'-help[show help]'
+  '1:SQLite database file:_files'
+  '(- :)2:SQL to run'
+)
+
+(( $+sqlite3 )) && options+=(
+  $^dashes'-bail[stop after hitting an error]'
+  '(-*batch -*interactive)'$^dashes'-batch[force batch I/O]'
+  '(-*batch -*interactive)'$^dashes'-interactive[force interactive I/O]'
+  $^dashes'-stats[print memory stats before each finalize]'
+)
+
+_arguments $options
-- 
1.7.8.3


                 reply	other threads:[~2012-01-22 20:24 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1327263846-5336-1-git-send-email-zsh@benizi.com \
    --to=zsh@benizi.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).