Subject: [PATCH] zsh locale completion
From: Marko Myllynen <[email-masked]>
To: [email-masked]
Date: Mon, 9 May 2016 15:55:00 +0300
List-Id: Zsh Workers List <zsh-workers.zsh.org>

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.

http://man7.org/linux/man-pages/man1/locale.1.html

---
 Completion/Unix/Command/_locale | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 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..00e5f8e
--- /dev/null
+++ b/Completion/Unix/Command/_locale
@@ -0,0 +1,28 @@
+#compdef locale
+
+local curcontext="$curcontext" state line expl ret=1
+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

Thanks,

-- 
Marko Myllynen