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 autolearn=ham
	autolearn_force=no version=3.4.1
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:reply-to:to:from:subject:organization:message-id
         :date:user-agent:mime-version:content-transfer-encoding;
        bh=6zSAWw9YvUl5bS+LusP0BBiZoaHBwlHBhxrwluE0uuk=;
        b=FP9N3QkmdYR6baxgnvF9rOCSGuw7M6p9foQU4dFgIMU9qGzrVBV/mc8s5OpBrYOFwf
         puzYVMXLvFbTInKofd7awn9v3xdhX2DdNVA0pxm5K5hJ0K+YNuUioZ/fAgTLzun3WiOM
         suvGfYusvjLM4mx2DAb+204B49oKoyKrZ4TlV4wldBjMhTZHnOE0tuH9nydd+t24npuy
         W4IoRSC/dN7dfjikKG2nhxVJDE2TJz74mftp/M/j7DYTu+bCMR95E4efJZxXjm0huyyH
         f664vTl3wEnnsUhJNnW7EM5XmxwM2D2iseMxeLRMXmrlbqDER0pGhnKXpVdjMXiBhScF
         Wu4w==
X-Gm-Message-State: ALyK8tLU7lgHHOGGpwPpZJXWee9lBEqd51EJQmBZ8LsSvQxKs+Q3CGf2NE+Rsix7zIHJMrc5
X-Received: by 10.194.116.195 with SMTP id jy3mr7534208wjb.36.1465915160778;
        Tue, 14 Jun 2016 07:39:20 -0700 (PDT)
Reply-To: Marko Myllynen <myllynen@redhat.com>
To: zsh workers <zsh-workers@zsh.org>
From: Marko Myllynen <myllynen@redhat.com>
Subject: [PATCH v5] zsh localedef completion
Organization: Red Hat
Message-ID: <57601714.4020209@redhat.com>
Date: Tue, 14 Jun 2016 17:39:16 +0300
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101
 Thunderbird/38.8.0
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
X-Seq: zsh-workers 38680

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 one thing here (not two anymore -
thanks to Daniel Shahaf for explaining the other one):

$ localedef -c<TAB>

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

As Eric Cook pointed out, there's life outside of GNU and this patch now
supports many non-GNU variants as well. 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. Minor option list
cleanup included as well on Eric's suggestion.

Baptiste Daroussin informed that even though there's no FreeBSD man
page for localedef(1) yet, it will be based on the same code as the
Dragonfly BSD variant in FreeBSD 11.

Based on comments from Eric and Oliver Kiddle and thinking it again,
it seems best to drop the -M 'm:{a-zA-Z}={A-Za-z} r:|-=* r:|=*' compadd
stanza (which is now done in the patch below).

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.freebsd.org/cgi/man.cgi?localedef
https://www.dragonflybsd.org/cgi/web-man?command=localedef&section=1

---
 Completion/Unix/Command/_localedef | 92 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 92 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..78d2319
--- /dev/null
+++ b/Completion/Unix/Command/_localedef
@@ -0,0 +1,92 @@
+#compdef localedef
+
+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 charmaps expl charmap _files && ret=0
+      else
+        typeset -a charmaps
+        charmaps=( ${(f)"$(locale -m)"} )
+        _wanted charmaps expl charmap compadd -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 locales expl locale compadd -a locales && ret=0
+    ;;
+  esac
+
+  return ret
+
+else
+
+  typeset -a u_opt bsd_opts
+  [[ $OSTYPE != darwin* ]] && u_opt=(
+      '-u+[specify target codeset]:codeset:_files'
+    )
+  [[ $OSTYPE == (freebsd*|dragonfly*) ]] && bsd_opts=(
+      '-D[create BSD-style output]' \
+      '-U[ignore undefined character symbols]' \
+      '-v[verbose deguggin output]' \
+      '-w+[specify width file]:width file:_files' \
+    )
+
+  _arguments -A "-*" -C \
+    '-c[force write despite of warnings]' \
+    '-f+[specify locale charmap file]:charmap:->charmap' \
+    '-i+[specify locale definition file]:locale file:_files' \
+    $u_opt \
+    $bsd_opts \
+    '1:path:_files' \
+    && return 0
+
+  case "$state" in
+    charmap)
+      if [[ $words[-1] == */* ]]; then
+        _wanted charmaps expl charmap _files && ret=0
+      else
+        typeset -a charmaps
+        charmaps=( ${(f)"$(locale -m)"} )
+        _wanted charmaps expl charmap compadd -a charmaps && ret=0
+      fi
+    ;;
+  esac
+
+  return ret
+
+fi

Thanks,

-- 
Marko Myllynen

