zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH v2] zsh locale completion
@ 2016-05-30 17:36 Marko Myllynen
  2016-06-02  3:32 ` Eric Cook
  0 siblings, 1 reply; 3+ messages in thread
From: Marko Myllynen @ 2016-05-30 17:36 UTC (permalink / raw)
  To: zsh workers

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] zsh locale completion
  2016-05-30 17:36 [PATCH v2] zsh locale completion Marko Myllynen
@ 2016-06-02  3:32 ` Eric Cook
  2016-06-02 11:51   ` Marko Myllynen
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Cook @ 2016-06-02  3:32 UTC (permalink / raw)
  To: zsh-workers

Tweaked it a little and tested it on freebsd, openbsd and netbsd.
I currently lack access to a dragonflybsd and solaris/illumos machine.

---
 Completion/Unix/Command/_locale | 84 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 84 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..87775be
--- /dev/null
+++ b/Completion/Unix/Command/_locale
@@ -0,0 +1,84 @@
+#compdef locale
+
+local curcontext="$curcontext" state state_descr line expl ret=1
+typeset -A opt_args; local -a specs aopts
+
+if _pick_variant gnu='(GNU|EGLIBC)' unix --version; then
+
+  local exargs="-? --help --usage -V --version"
+
+  aopts=( -A "-*" -C -S -s )
+  specs=(
+    '(- *)'{-\?,--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'
+  )
+
+elif [[ $OSTYPE == openbsd* ]]; then
+
+  specs=(
+    '(-m)-a[list all available locales]'
+    '(-a)-m[list all available charmaps]'
+  )
+
+else
+
+  aopts=( -C -A "-*" )
+  specs=(
+    - set1
+    '-a[list all available locales]'
+    - set2
+    '-m[list all available charmaps]'
+    - set3
+    '-c[print also locale category]'
+    '-k[print also keyword of each value]'
+    '*:name:->catkey'
+  )
+fi
+
+_arguments $aopts : $specs && ret=0
+
+if [[ $state == catkey ]]; then
+  typeset -aU cats keys
+
+  case $OSTYPE in
+    *bsd*)
+      # keywords from comparing locale -k list on netbsd and freebsd
+      # the additional keywords freebsd supports will be added via
+      # the reassignment of keys
+      keys+=(
+        charmap decimal_point thousands_sep grouping radixchar thousep int_curr_symbol
+        currency_symbol mon_decimal_point mon_thousands_sep mon_grouping positive_sign
+        negative_sign int_frac_digits frac_digits p_cs_precedes p_sep_by_space n_cs_precedes
+        n_sep_by_space p_sign_posn n_sign_posn int_p_cs_precedes int_p_sep_by_space
+        int_n_cs_precedes int_n_sep_by_space int_p_sign_posn int_n_sign_posn d_t_fmt d_fmt
+        t_fmt am_str pm_str t_fmt_ampm day_1 day_2 day_3 day_4 day_5 day_6 day_7 abday_1
+        abday_2 abday_3 abday_4 abday_5 abday_6 abday_7 mon_1 mon_2 mon_3 mon_4 mon_5 mon_6
+        mon_7 mon_8 mon_9 mon_10 mon_11 mon_12 abmon_1 abmon_2 abmon_3 abmon_4 abmon_5
+        abmon_6 abmon_7 abmon_8 abmon_9 abmon_10 abmon_11 abmon_12 era era_d_fmt era_d_t_fmt
+        era_t_fmt alt_digits yesexpr noexpr yesstr nostr
+      );|
+    (free|net|dragonfly)bsd*) (( words[(I)-k] )) && keys+=(list);;
+    *)
+      cats=( ${${${(f)"$(locale)"}%=*}%(LANG|LANGUAGE|LC_ALL)} )
+    ;;
+  esac
+
+  keys=( $keys ${${(f)"$(locale -k $cats 2>/dev/null)"}%=*} )
+  if [[ $OSTYPE == freebsd* ]] && (( words[(I)list] )); then
+    _message -e values prefix && ret=0
+  else
+    _wanted values expl name compadd "$@" -a - cats keys && ret=0
+  fi
+fi
+
+return ret
-- 
2.6.6


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] zsh locale completion
  2016-06-02  3:32 ` Eric Cook
@ 2016-06-02 11:51   ` Marko Myllynen
  0 siblings, 0 replies; 3+ messages in thread
From: Marko Myllynen @ 2016-06-02 11:51 UTC (permalink / raw)
  To: zsh-workers

Hi,

On 2016-06-02 06:32, Eric Cook wrote:
> Tweaked it a little and tested it on freebsd, openbsd and netbsd.

Right, things seem to look a bit different when actually being able to
test things and not just read the man pages (e.g: FreeBSD vs NetBSD
locale(1)).

For glibc things work still as before so all good on that front.

Thanks,

-- 
Marko Myllynen


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-06-02 12:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-30 17:36 [PATCH v2] zsh locale completion Marko Myllynen
2016-06-02  3:32 ` Eric Cook
2016-06-02 11:51   ` Marko Myllynen

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).