zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] zsh locale completion
@ 2016-05-09 12:55 Marko Myllynen
  2016-05-09 22:14 ` Daniel Shahaf
  0 siblings, 1 reply; 6+ messages in thread
From: Marko Myllynen @ 2016-05-09 12:55 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.

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


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

* Re: [PATCH] zsh locale completion
  2016-05-09 12:55 [PATCH] zsh locale completion Marko Myllynen
@ 2016-05-09 22:14 ` Daniel Shahaf
  2016-05-10 15:32   ` Marko Myllynen
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Shahaf @ 2016-05-09 22:14 UTC (permalink / raw)
  To: Marko Myllynen; +Cc: zsh-workers

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/


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

* Re: [PATCH] zsh locale completion
  2016-05-09 22:14 ` Daniel Shahaf
@ 2016-05-10 15:32   ` Marko Myllynen
  2016-05-28 14:38     ` Eric Cook
  2016-05-28 14:49     ` Eric Cook
  0 siblings, 2 replies; 6+ messages in thread
From: Marko Myllynen @ 2016-05-10 15:32 UTC (permalink / raw)
  To: Daniel Shahaf; +Cc: zsh-workers

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,

-- 
Marko Myllynen


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

* Re: [PATCH] zsh locale completion
  2016-05-10 15:32   ` Marko Myllynen
@ 2016-05-28 14:38     ` Eric Cook
  2016-05-28 14:49     ` Eric Cook
  1 sibling, 0 replies; 6+ messages in thread
From: Eric Cook @ 2016-05-28 14:38 UTC (permalink / raw)
  To: zsh-workers

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


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

* Re: [PATCH] zsh locale completion
  2016-05-10 15:32   ` Marko Myllynen
  2016-05-28 14:38     ` Eric Cook
@ 2016-05-28 14:49     ` Eric Cook
  2016-05-29 15:50       ` Marko Myllynen
  1 sibling, 1 reply; 6+ messages in thread
From: Eric Cook @ 2016-05-28 14:49 UTC (permalink / raw)
  To: zsh-workers

On 05/10/2016 11:32 AM, Marko Myllynen wrote:

> +_arguments -A -C -S -s \

_argument's -A option expects a argument,
do you actually intent for -C to be the argument, or a option to _arguments?

(you seem to do this in your localedef patch too)


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

* Re: [PATCH] zsh locale completion
  2016-05-28 14:49     ` Eric Cook
@ 2016-05-29 15:50       ` Marko Myllynen
  0 siblings, 0 replies; 6+ messages in thread
From: Marko Myllynen @ 2016-05-29 15:50 UTC (permalink / raw)
  To: zsh-workers

Hi,

On 2016-05-28 17:49, Eric Cook wrote:
> On 05/10/2016 11:32 AM, Marko Myllynen wrote:
> 
>> +_arguments -A -C -S -s \
> 
> _argument's -A option expects a argument,
> do you actually intent for -C to be the argument, or a option to _arguments?
> 
> (you seem to do this in your localedef patch too)

Hmm, interesting, thanks for pointing that out, on RHEL 7 / zsh-5.0.2
the man page had this:

    _arguments [ -nswWACRS ] [ -O name ] [ -M matchspec ] [ : ] spec ...

But it's been fixed since then in d5ba3ed. Will follow up with an
updated version.

Thanks,

-- 
Marko Myllynen


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

end of thread, other threads:[~2016-05-29 16:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-09 12:55 [PATCH] zsh locale completion Marko Myllynen
2016-05-09 22:14 ` Daniel Shahaf
2016-05-10 15:32   ` Marko Myllynen
2016-05-28 14:38     ` Eric Cook
2016-05-28 14:49     ` Eric Cook
2016-05-29 15:50       ` 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).