zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH v2] zsh localedef completion
@ 2016-05-30 17:36 Marko Myllynen
  2016-05-31 16:44 ` Baptiste Daroussin
  0 siblings, 1 reply; 4+ messages in thread
From: Marko Myllynen @ 2016-05-30 17:36 UTC (permalink / raw)
  To: zsh workers

Hi,

Below is zsh completions for the localedef(1) command, I've tested this
on RHEL 7 against the glibc provided localedef command. Otherwise it
works nicely but I'm a bit wondering two things here:

$ localedef -Afoo -<TAB>

offers --alias-file (unexpected to me) alongside the others but

$ localedef --alias-file=foo -<TAB>

does not offer -A (IMHO expected).

$ localedef -c<TAB>

offers also V/? although I hoped them to get excluded in that case.

Anyway, I don't think neither of these are critical issues so I think
this would be already worth merging as-is but if you happen to know the
needed tweaks to address those issues all the better.

As Eric Cook pointed out, there's life outside of GNU and this patch now
supports Darwin/Dragonfly/GNU/POSIX. Since I don't have access to a
Solaris system I didn't implement that yet, would be probably pretty
straightforward but would be good to actually test it.

As with locale(1) completion, I chose to duplicate few lines so that if
something needs to be changed for non-GNU which I haven't tested, it's
probably easier to tweak the already separate if-block then.

References:

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/localedef.html
http://man7.org/linux/man-pages/man1/localedef.1.html
https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man1/localedef.1.html
https://docs.oracle.com/cd/E26502_01/html/E29030/localedef-1.html
https://www.dragonflybsd.org/cgi/web-man?command=localedef&section=1

---
 Completion/Unix/Command/_localedef | 98 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 98 insertions(+)
 create mode 100644 Completion/Unix/Command/_localedef

diff --git a/Completion/Unix/Command/_localedef b/Completion/Unix/Command/_localedef
new file mode 100644
index 0000000..4f37c56
--- /dev/null
+++ b/Completion/Unix/Command/_localedef
@@ -0,0 +1,98 @@
+#compdef localedef
+
+# TODO: Solaris opts
+
+local curcontext="$curcontext" state line expl ret=1
+typeset -A opt_args
+
+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]' \
+    "(-A --alias-file= $exargs)"{-A+,--alias-file=}'[specify locale alias file]:alias file:_files' \
+    "($exargs)--prefix=[specify path prefix]:prefix:_files" \
+    "(-c --force $exargs)"{-c,--force}'[force write despite of warnings]' \
+    "(-v --verbose $exargs)"{-v,--verbose}'[display additional information]' \
+    "($exargs)--quiet[suppress messages and warnings]" \
+    - set1 \
+    "(-f --charmap= $exargs)"{-f+,--charmap=}'[specify locale charmap file]:charmap:->charmap' \
+    "(-i --inputfile= $exargs)"{-i+,--inputfile=}'[specify locale definition file]:locale file:_files' \
+    "(-u --repertoire-map= $exargs)"{-u+,--repertoire-map=}'[specify repertoire map file]:repertoire map file:_files' \
+    '1:path:_files' \
+    - set2 \
+    "(--list-archive $exargs)--list-archive[list locales in archive]" \
+    - set3 \
+    "(--delete-from-archive $exargs)--delete-from-archive[delete locale from archive]" \
+    '*:locale:->locale' \
+    - set4 \
+    "(--add-to-archive $exargs)--add-to-archive[add locale to archive]" \
+    "(--replace $exargs)--replace[replace locale in archive]" \
+    "(--no-archive $exargs)--no-archive[use subdir not archive]" \
+    '*:compiled path:_files -/' \
+    && return 0
+
+  case "$state" in
+    charmap)
+      if [[ $words[-1] == */* ]]; then
+        _wanted values expl charmap _files && ret=0
+      else
+        typeset -a charmaps
+        charmaps=( ${(f)"$(locale -m)"} )
+        _wanted values expl charmap compadd "$@" \
+          -M 'm:{a-zA-Z}={A-Za-z} r:|-=* r:|=*' \
+          -a - charmaps && ret=0
+      fi
+    ;;
+    locale)
+      typeset -a locales
+      local pref=${opt_args[--prefix]}
+      local p=${pref:+--prefix}
+      locales=( ${(f)"$(localedef --list-archive $p $pref)"} )
+      _wanted values expl locale compadd "$@" -a - locales && ret=0
+    ;;
+  esac
+
+  return ret
+
+else
+
+  typeset -a u_opt dragonfly_opts
+  [[ $OSTYPE != darwin* ]] && u_opt=(
+      "(-u)"-u+'[specify target codeset]:codeset:_files'
+    )
+  [[ $OSTYPE == dragonfly* ]] && dragonfly_opts=(
+      "(-D)"-D'[create BSD-style output]' \
+      "(-U)"-U'[ignore undefined character symbols]' \
+      "(-v)"-v'[verbose deguggin output]' \
+      "(-w)"-w+'[specify width file]:width file:_files' \
+    )
+
+  _arguments -A "-*" -C \
+    "(-c)"-c'[force write despite of warnings]' \
+    "(-f)"-f+'[specify locale charmap file]:charmap:->charmap' \
+    "(-i)"-i+'[specify locale definition file]:locale file:_files' \
+    $u_opt \
+    $dragonfly_opts \
+    '1:path:_files' \
+    && return 0
+
+  case "$state" in
+    charmap)
+      if [[ $words[-1] == */* ]]; then
+        _wanted values expl charmap _files && ret=0
+      else
+        typeset -a charmaps
+        charmaps=( ${(f)"$(locale -m)"} )
+        _wanted values expl charmap compadd "$@" \
+          -M 'm:{a-zA-Z}={A-Za-z} r:|-=* r:|=*' \
+          -a - charmaps && ret=0
+      fi
+    ;;
+  esac
+
+  return ret
+
+fi

Thanks,

-- 
Marko Myllynen


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

* Re: [PATCH v2] zsh localedef completion
  2016-05-30 17:36 [PATCH v2] zsh localedef completion Marko Myllynen
@ 2016-05-31 16:44 ` Baptiste Daroussin
  2016-05-31 18:31   ` Marko Myllynen
  0 siblings, 1 reply; 4+ messages in thread
From: Baptiste Daroussin @ 2016-05-31 16:44 UTC (permalink / raw)
  To: Marko Myllynen; +Cc: zsh workers

FreeBSD expect the same options as Dragonfly given we share the same code here

Can you please add freebsd ?

2016-05-30 19:36 GMT+02:00 Marko Myllynen <myllynen@redhat.com>:
> Hi,
>
> Below is zsh completions for the localedef(1) command, I've tested this
> on RHEL 7 against the glibc provided localedef command. Otherwise it
> works nicely but I'm a bit wondering two things here:
>
> $ localedef -Afoo -<TAB>
>
> offers --alias-file (unexpected to me) alongside the others but
>
> $ localedef --alias-file=foo -<TAB>
>
> does not offer -A (IMHO expected).
>
> $ localedef -c<TAB>
>
> offers also V/? although I hoped them to get excluded in that case.
>
> Anyway, I don't think neither of these are critical issues so I think
> this would be already worth merging as-is but if you happen to know the
> needed tweaks to address those issues all the better.
>
> As Eric Cook pointed out, there's life outside of GNU and this patch now
> supports Darwin/Dragonfly/GNU/POSIX. Since I don't have access to a
> Solaris system I didn't implement that yet, would be probably pretty
> straightforward but would be good to actually test it.
>
> As with locale(1) completion, I chose to duplicate few lines so that if
> something needs to be changed for non-GNU which I haven't tested, it's
> probably easier to tweak the already separate if-block then.
>
> References:
>
> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/localedef.html
> http://man7.org/linux/man-pages/man1/localedef.1.html
> https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man1/localedef.1.html
> https://docs.oracle.com/cd/E26502_01/html/E29030/localedef-1.html
> https://www.dragonflybsd.org/cgi/web-man?command=localedef&section=1
>
> ---
>  Completion/Unix/Command/_localedef | 98 ++++++++++++++++++++++++++++++++++++++
>  1 file changed, 98 insertions(+)
>  create mode 100644 Completion/Unix/Command/_localedef
>
> diff --git a/Completion/Unix/Command/_localedef b/Completion/Unix/Command/_localedef
> new file mode 100644
> index 0000000..4f37c56
> --- /dev/null
> +++ b/Completion/Unix/Command/_localedef
> @@ -0,0 +1,98 @@
> +#compdef localedef
> +
> +# TODO: Solaris opts
> +
> +local curcontext="$curcontext" state line expl ret=1
> +typeset -A opt_args
> +
> +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]' \
> +    "(-A --alias-file= $exargs)"{-A+,--alias-file=}'[specify locale alias file]:alias file:_files' \
> +    "($exargs)--prefix=[specify path prefix]:prefix:_files" \
> +    "(-c --force $exargs)"{-c,--force}'[force write despite of warnings]' \
> +    "(-v --verbose $exargs)"{-v,--verbose}'[display additional information]' \
> +    "($exargs)--quiet[suppress messages and warnings]" \
> +    - set1 \
> +    "(-f --charmap= $exargs)"{-f+,--charmap=}'[specify locale charmap file]:charmap:->charmap' \
> +    "(-i --inputfile= $exargs)"{-i+,--inputfile=}'[specify locale definition file]:locale file:_files' \
> +    "(-u --repertoire-map= $exargs)"{-u+,--repertoire-map=}'[specify repertoire map file]:repertoire map file:_files' \
> +    '1:path:_files' \
> +    - set2 \
> +    "(--list-archive $exargs)--list-archive[list locales in archive]" \
> +    - set3 \
> +    "(--delete-from-archive $exargs)--delete-from-archive[delete locale from archive]" \
> +    '*:locale:->locale' \
> +    - set4 \
> +    "(--add-to-archive $exargs)--add-to-archive[add locale to archive]" \
> +    "(--replace $exargs)--replace[replace locale in archive]" \
> +    "(--no-archive $exargs)--no-archive[use subdir not archive]" \
> +    '*:compiled path:_files -/' \
> +    && return 0
> +
> +  case "$state" in
> +    charmap)
> +      if [[ $words[-1] == */* ]]; then
> +        _wanted values expl charmap _files && ret=0
> +      else
> +        typeset -a charmaps
> +        charmaps=( ${(f)"$(locale -m)"} )
> +        _wanted values expl charmap compadd "$@" \
> +          -M 'm:{a-zA-Z}={A-Za-z} r:|-=* r:|=*' \
> +          -a - charmaps && ret=0
> +      fi
> +    ;;
> +    locale)
> +      typeset -a locales
> +      local pref=${opt_args[--prefix]}
> +      local p=${pref:+--prefix}
> +      locales=( ${(f)"$(localedef --list-archive $p $pref)"} )
> +      _wanted values expl locale compadd "$@" -a - locales && ret=0
> +    ;;
> +  esac
> +
> +  return ret
> +
> +else
> +
> +  typeset -a u_opt dragonfly_opts
> +  [[ $OSTYPE != darwin* ]] && u_opt=(
> +      "(-u)"-u+'[specify target codeset]:codeset:_files'
> +    )
> +  [[ $OSTYPE == dragonfly* ]] && dragonfly_opts=(
> +      "(-D)"-D'[create BSD-style output]' \
> +      "(-U)"-U'[ignore undefined character symbols]' \
> +      "(-v)"-v'[verbose deguggin output]' \
> +      "(-w)"-w+'[specify width file]:width file:_files' \
> +    )
> +
> +  _arguments -A "-*" -C \
> +    "(-c)"-c'[force write despite of warnings]' \
> +    "(-f)"-f+'[specify locale charmap file]:charmap:->charmap' \
> +    "(-i)"-i+'[specify locale definition file]:locale file:_files' \
> +    $u_opt \
> +    $dragonfly_opts \
> +    '1:path:_files' \
> +    && return 0
> +
> +  case "$state" in
> +    charmap)
> +      if [[ $words[-1] == */* ]]; then
> +        _wanted values expl charmap _files && ret=0
> +      else
> +        typeset -a charmaps
> +        charmaps=( ${(f)"$(locale -m)"} )
> +        _wanted values expl charmap compadd "$@" \
> +          -M 'm:{a-zA-Z}={A-Za-z} r:|-=* r:|=*' \
> +          -a - charmaps && ret=0
> +      fi
> +    ;;
> +  esac
> +
> +  return ret
> +
> +fi
>
> Thanks,
>
> --
> Marko Myllynen


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

* Re: [PATCH v2] zsh localedef completion
  2016-05-31 16:44 ` Baptiste Daroussin
@ 2016-05-31 18:31   ` Marko Myllynen
  2016-06-01  9:02     ` Baptiste Daroussin
  0 siblings, 1 reply; 4+ messages in thread
From: Marko Myllynen @ 2016-05-31 18:31 UTC (permalink / raw)
  To: Baptiste Daroussin; +Cc: zsh workers

Hi,

On 2016-05-31 19:44, Baptiste Daroussin wrote:
> FreeBSD expect the same options as Dragonfly given we share the same code here
> 
> Can you please add freebsd ?

Yes, it could be done easily but I'm a bit surprised about this given
that there seems to be no man page available for FreeBSD localedef:

https://www.freebsd.org/cgi/man.cgi?localedef

 Sorry, no data found for `localedef'. Please try a keyword search.

Thanks,

-- 
Marko Myllynen


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

* Re: [PATCH v2] zsh localedef completion
  2016-05-31 18:31   ` Marko Myllynen
@ 2016-06-01  9:02     ` Baptiste Daroussin
  0 siblings, 0 replies; 4+ messages in thread
From: Baptiste Daroussin @ 2016-06-01  9:02 UTC (permalink / raw)
  To: Marko Myllynen; +Cc: zsh workers

Actually localedef will appear in FreeBSD 11. Our release cycle is a
bit longer than the one from dragonfly :)

The online manpage have not yet been updated for freebsd 11. But
localedef is exactly the same as the one from Dragonfly (actually also
the same as the one in illumos beside the -D option)

Best regards,
Bapt

2016-05-31 20:31 GMT+02:00 Marko Myllynen <myllynen@redhat.com>:
> Hi,
>
> On 2016-05-31 19:44, Baptiste Daroussin wrote:
>> FreeBSD expect the same options as Dragonfly given we share the same code here
>>
>> Can you please add freebsd ?
>
> Yes, it could be done easily but I'm a bit surprised about this given
> that there seems to be no man page available for FreeBSD localedef:
>
> https://www.freebsd.org/cgi/man.cgi?localedef
>
>  Sorry, no data found for `localedef'. Please try a keyword search.
>
> Thanks,
>
> --
> Marko Myllynen


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

end of thread, other threads:[~2016-06-01  9:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-30 17:36 [PATCH v2] zsh localedef completion Marko Myllynen
2016-05-31 16:44 ` Baptiste Daroussin
2016-05-31 18:31   ` Marko Myllynen
2016-06-01  9:02     ` Baptiste Daroussin

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