zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: zsh-workers@sunsite.dk (Zsh hackers list)
Subject: PATCH: completion for locate.
Date: Wed, 27 Sep 2006 14:56:23 +0100	[thread overview]
Message-ID: <200609271356.k8RDuNZ5025572@news01.csr.com> (raw)

Completion for GNU locate, slocate, mlocate, for options since there's
no way of completing patterns.  Decides the type; GNU locate isn't
properly tested but they're all pretty similar.  Currently misses some
tricks with paths as noted; also doesn't handle updatedb, except in the
case of slocate where that's built in.

Index: Completion/Unix/Command/_locate
===================================================================
RCS file: Completion/Unix/Command/_locate
diff -N Completion/Unix/Command/_locate
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ Completion/Unix/Command/_locate	27 Sep 2006 13:55:39 -0000
@@ -0,0 +1,111 @@
+#compdef locate mlocate slocate
+
+# Decide if we are using mlocate or slocate.
+local ltype basename=${words[0]:t} input
+# If we can't, use this guess.
+local best_guess=mlocate
+
+case $basename in
+  ([ms]locate)
+  ltype=$basename
+  ;;
+
+  (locate)
+  input="$(_call_program locate $words[0] -V)"
+  case $input in
+    (*mlocate*)
+    ltype=mlocate
+    ;;
+
+    (*(#i)secure locate*)
+    ltype=slocate
+    ;;
+
+    (*(#i)gnu locate*)
+    ltype=gnu
+    ;;
+
+    # guess
+    (*)
+    ltype=$best_guess
+    ;;
+  esac
+  ;;
+
+  (*)
+  # too dangerous to run: guess
+  ltype=$best_guess
+esac
+
+case $ltype in
+  (mlocate)
+  # actually, -d can take a colon-separate list
+  # -r/--regexp mean no normal arguments, so shouldn't complete
+  # -m and --mmap are ignored, so don't bother
+  # -s and --stdio likewise
+  _arguments -s : \
+    {-b,--basename}'[Match only the basename of files in the database]' \
+    {-c,--count}'[Output the number of matching entries]' \
+    {-d,--database=}'[Use alternative database]:database:_files' \
+    {-e,--existing}'[Restrict display to existing files]' \
+    {-L,--follow}'[Follow symbolic links to find existing files (default)]' \
+    {-h,--help}'[Show help]' \
+    {-i,--ignore-case}'[Ignore case distinctions in patterns]' \
+    {-l,-n,--limit=}'[Limit search results]:file limit: ' \
+    {-P,-H,--nofollow}'[Don'\''t follow symbolic links]' \
+    {-0,--null}'[Output separated by NUL characters]' \
+    {-S,--statistics}'[Show database statistics]' \
+    {-q,--quiet}'[Don'\''t report errors]' \
+    {-r,--regexp=}'[Search for given basic regexp]:basic regexp: ' \
+    --regex'[Patterns are extended regexps]' \
+    {-V,--version}'[Show version]' \
+    {-w,--wholename}'[Match entire file path (default)]' \
+    '*:pattern: '
+  ;;
+
+  (slocate)
+  # -d can take path
+  # -e can take a comma-separated list of directories.
+  # -f should complete list of file system types like mount
+  _arguments -s : \
+    -u'[Create slocate database starting at path /]' \
+    -U'[Create slocate database starting at given path]:directory:_files -/' \
+    -c'[Parse GNU locate updatedb with -u, -U]' \
+    -e'[Exclude directories with -u, -U]:directories:_files -/' \
+    -f'[Exclude file system types from db with -u, -U]:file system:_file_systems' \
+    -l'[Security level]:level:(0 1)' \
+    -q'[Quiet mode]' \
+    -n'[Limit search results]:file limit: ' \
+    -i'[Case insensitive search]' \
+    {-r,--regexp=}'[Use basic regular expression]:regexp: ' \
+    {-o,--output=}'[Specify database to create]:database:_files' \
+    {-d,--database=}'[Specify database to search]:database:_files' \
+    {-h,--help}'[Display help]' \
+    {-v,--verbose}'[Display files when creating database]' \
+    {-V,--version}'[Display version]' \
+    '*:pattern: '
+  ;;
+
+  (gnu)
+  _arguments -s : \
+    {-d,--database=}'[Use alternative database]:database:_files' \
+    {-e,--existing}'[Restrict display to existing files]' \
+    {-E,--non-existing}'[Allow display of nonexistent files (default)]' \
+    {-i,--ignore-case}'[Ignore case distinctions in patterns]' \
+    {-w,--wholename}'[Match entire file path (default)]' \
+    {-b,--basename}'[Match only the basename of files in the database]' \
+    {-l,-n,--limit=}'[Limit search results]:file limit: ' \
+    {-S,--statistics}'[Show database statistics]' \
+    {-0,--null}'[Output separated by NUL characters]' \
+    {-c,--count}'[Output the number of matching entries]' \
+    {-P,-H,--nofollow}'[Don'\''t follow symbolic links]' \
+    {-L,--follow}'[Follow symbolic links to find existing files (default)]' \
+    {-A,-all}'[Match all arguments instead of at least one]' \
+    {-p,--print}'[Include search results with statistics or count]' \
+    {-r,--regex=}'[Patterns are regular expressions]:basic regexp: ' \
+    --regextype='[Select type of regular expression]' \
+    {-V,--version}'[Show version]' \
+    --help'[Show help]' \
+    '*:pattern: '
+  ;;
+esac

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


To access the latest news from CSR copy this link into a web browser:  http://www.csr.com/email_sig.php


                 reply	other threads:[~2006-09-27 14:42 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=200609271356.k8RDuNZ5025572@news01.csr.com \
    --to=pws@csr.com \
    --cc=zsh-workers@sunsite.dk \
    /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).