zsh-workers
 help / color / mirror / code / Atom feed
From: Marko Myllynen <myllynen@redhat.com>
To: zsh workers <zsh-workers@zsh.org>
Subject: [PATCH v2] zsh locale completion
Date: Mon, 30 May 2016 20:36:09 +0300	[thread overview]
Message-ID: <574C7A09.7010800@redhat.com> (raw)

Hi,

Below is zsh completions for the locale(1) command, I've tested this on
RHEL 7 against the glibc provided locale command. Otherwise it works
nicely but I'm a bit wondering why after "locale -a<TAB>" I'm getting
all other options offered, I would have thought getting -v offered only.

On Eric Cook's suggestion supports now GNU/OpenBSD/POSIX. I duplicated
the category/keyword handling under GNU/POSIX sections as I don't have
any non-GNU systems to test on and if any changes are needed for non-GNU
it's probably easier to tweak the already separate if-block then.

References:

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/locale.html
http://man7.org/linux/man-pages/man1/locale.1.html
https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man1/locale.1.html
https://docs.oracle.com/cd/E26502_01/html/E29030/locale-1.html
https://www.freebsd.org/cgi/man.cgi?locale
http://netbsd.gw.com/cgi-bin/man-cgi?locale+1+NetBSD-current
http://man.openbsd.org/locale.1
https://www.dragonflybsd.org/cgi/web-man?command=locale&section=1

---
 Completion/Unix/Command/_locale | 68 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)
 create mode 100644 Completion/Unix/Command/_locale

diff --git a/Completion/Unix/Command/_locale b/Completion/Unix/Command/_locale
new file mode 100644
index 0000000..3b3aa22
--- /dev/null
+++ b/Completion/Unix/Command/_locale
@@ -0,0 +1,68 @@
+#compdef locale
+
+# TODO: FreeBSD: locale -k list [prefix]
+
+local curcontext="$curcontext" state line expl ret=1
+
+if _pick_variant gnu='(GNU|EGLIBC)' unix --version; then
+
+  local exargs="-? --help --usage -V --version"
+
+  _arguments -A "-*" -C -S -s \
+    '(- *)'{-\?,--help}'[display help information]' \
+    '(- *)--usage[display a short usage message]' \
+    '(- *)'{-V,--version}'[print program version]' \
+    - set1 \
+    "(-a --all-locales $exargs)"{-a,--all-locales}'[list all available locales]' \
+    "(-v --verbose $exargs)"{-v,--verbose}'[display additional information]' \
+    - set2 \
+    "(-m --charmaps $exargs)"{-m,--charmaps}'[list all available charmaps]' \
+    - set3 \
+    "(-c --category-name $exargs)"{-c,--category-name}'[print also locale category]' \
+    "(-k --keyword-name $exargs)"{-k,--keyword-name}'[print also keyword of each value]' \
+    '*:name:->catkey' \
+    && return 0
+
+  if [[ $state == catkey ]]; then
+    typeset -a cats keys
+    cats=( ${${${(f)"$(locale)"}%=*}%(LANG|LANGUAGE|LC_ALL)} )
+    keys=( ${${(f)"$(locale -k $cats 2>/dev/null)"}%=*} )
+    _wanted values expl name compadd "$@" -a - cats keys && ret=0
+  fi
+
+  return ret
+
+elif [[ $OSTYPE == openbsd* ]]; then
+
+  _arguments \
+    - set1 \
+    "(-a)"-a'[list all available locales]' \
+    - set2 \
+    "(-m)"-m'[list all available charmaps]' \
+    && return 0
+
+  return ret
+
+else
+
+  _arguments -A "-*" -C \
+    - set1 \
+    "(-a)"-a'[list all available locales]' \
+    - set2 \
+    "(-m)"-m'[list all available charmaps]' \
+    - set3 \
+    "(-c)"-c'[print also locale category]' \
+    "(-k)"-k'[print also keyword of each value]' \
+    '*:name:->catkey' \
+    && return 0
+
+  if [[ $state == catkey ]]; then
+    typeset -a cats keys
+    cats=( ${${${(f)"$(locale)"}%=*}%(LANG|LANGUAGE|LC_ALL)} )
+    keys=( ${${(f)"$(locale -k $cats 2>/dev/null)"}%=*} )
+    _wanted values expl name compadd "$@" -a - cats keys && ret=0
+  fi
+
+  return ret
+
+fi

Thanks,

-- 
Marko Myllynen


             reply	other threads:[~2016-05-30 17:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-30 17:36 Marko Myllynen [this message]
2016-06-02  3:32 ` Eric Cook
2016-06-02 11:51   ` Marko Myllynen

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=574C7A09.7010800@redhat.com \
    --to=myllynen@redhat.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).