Subject: Re: [PATCH] zsh locale completion
From: Eric Cook <[email-masked]>
To: [email-masked]
Date: Sat, 28 May 2016 10:38:51 -0400
List-Id: Zsh Workers List <zsh-workers.zsh.org>

On 05/10/2016 11:32 AM, Marko Myllynen wrote:
> Hi,
> 
> On 2016-05-10 01:14, Daniel Shahaf wrote:
>> Marko Myllynen wrote on Mon, May 09, 2016 at 15:55:00 +0300:
>>> +++ b/Completion/Unix/Command/_locale
>>> @@ -0,0 +1,28 @@
>>> +local curcontext="$curcontext" state line expl ret=1
>> ⋮
>>> +_arguments -A -C -S -s \
>> ⋮
>>> +  '*:name:->catkey' \
>>> +  && return=0
>>
>> Typo: s/return/ret/
> 
> Good catch - updated patch below. It seems that using return is
> required as otherwise we end up inside the if-statement even in
> cases like locale -<tab>.
> 
> ---
>  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..af6e90c
> --- /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,
> 

Could you also test the version locale? possibly with _pick_variant and if the locale(1)
isn't glibc's locale; only present the options mandated by posix?[1]
also for bonus points, openbsd's locale only has the options -a and -m

[1] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/locale.html