Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm
Precedence: bulk
X-No-Archive: yes
List-Id: Zsh Workers List <zsh-workers.zsh.org>
List-Post: <mailto:zsh-workers@zsh.org>
List-Help: <mailto:zsh-workers-help@zsh.org>
X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM
	autolearn=ham autolearn_force=no version=3.4.1
Subject: Re: [PATCH v2] zsh locale completion
To: zsh-workers@zsh.org
References: <574C7A09.7010800@redhat.com>
From: Eric Cook <llua@gmx.com>
Message-ID: <db4c6937-9a98-ae57-1f3f-01a034936f76@gmx.com>
Date: Wed, 1 Jun 2016 23:32:12 -0400
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
 Thunderbird/45.1.0
MIME-Version: 1.0
In-Reply-To: <574C7A09.7010800@redhat.com>
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
X-Provags-ID: V03:K0:j1o9+RTVB6K+oNWo0Ru/pxaEJSXyt7xFhbzrCaopPl+kBm63iJM
 sLY+y7WtgJI+/gfzT6vdy206CCBygdv6/XzxQS62gc6MLIpMlWS1NXfwmxhEitmlsDWs3mK
 SFLpSnkACLY8kSu3ly2yHyt5G17YvmMrXYjeXI2CMXMbQ8i+dijsB8LKXKzdZ9Y0C2WeTZe
 LUJEZIAcKt4hJhV3AfG7A==
X-UI-Out-Filterresults: notjunk:1;V01:K0:VW1i3Gq1wyw=:t3krJoFgYqzx/kv6Nz7tfa
 Q/UhnIMbxN1FflsGvsNPBbX335fjG/JmqTdU8WTE5DjPfRXh14OLcS5IJKF3zbxTSi6JoFSTi
 2s/wP0yHn35576a8WZ8oabRYtCBl1/5ldjniPaHd4ZaKLhNWgi97vOUgoFNxaWtythIZ2sIVl
 eiPUo6lrVNwSP9rsd4t5N+HCwMM1XNO2Wyv8LblNWiv7qiHmC0W5kDqtp/9Fv2Muq8xPB8ek7
 aa3nSVsgWfK1/NYmSXBL2oNFpGdro8ICsIH5bqAL9mTrVCBUZDKbXoEKtczyTY17norn3IfBe
 4ELVYiFgroyrKqzx7qczKFUCIBogQFr/u/C4+JiDbKn6JJb2LB3Ps2OOANm38sF2cTwYfsEP+
 tBZBx6fb0/Ym7utwxNXBHI2NcPhgR+bA2El0K4LNSPWntoHVOttn55OEqzU0i2IO67rnFwH1N
 B3InsCkL+qwUHI4aAKASu271XAkhq3UcgCc3H/4w4u5xkj20Abwn7LdkR1lm4ZolxrnZZNaEO
 ljnpQg4PtLvwcJ7QSzcrRqjUxfnpDX5c4WZJz2jlIQURObHJv48NsypdKtQkYVuXESEBXh0vx
 2ux255Y2Z8OiR6nnx5IbYoqKcpNceLETr6yQL2KXSz7kk4INLGx9NtpXzXOAiSpBmulfjS6Uh
 e6FFqnbZaSTRPcGr0AN0CMm0kQDZ3HpR+sJtCo4+H0ltulrDyD7ICux0CSIUVYjc52OA2d6ze
 DIzt0+Ru4qTxDjAhMwCstPximA8Ks1kSvMpihAqHX+J8AXZdpYT+8Lx9+OviAAAJ9f3moUpB7
 VZh64uy
X-Seq: zsh-workers 38567

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

