From: "Jun T." <takimoto-j@kba.biglobe.ne.jp>
To: "zsh-workers@zsh.org" <zsh-workers@zsh.org>
Subject: PATCH: _iconv: support libiconv version of iconv
Date: Tue, 26 Nov 2013 12:52:26 +0900 [thread overview]
Message-ID: <5E95BB3E-EA71-4261-AC16-305A1068C3C9@kba.biglobe.ne.jp> (raw)
There are two variants of GNU iconv, one from glibc and the other from
libiconv, and the lists of encodings output by 'iconv --list' are in
different formats; one encoding per line in the former, while in the latter
all the equivalent encodings (aliases) are in a single line (separated by
spaces).
Most (all?) of Linuxes use glibc version, but Mac OS X uses libiconv.
The patch below is to add support for the libiconv version.
I also added '//IGNORE' as a possible suffix to encoding
(and offer suffixes only for -t/--to-code and not for -f/--from-code).
diff --git a/Completion/Unix/Command/_iconv b/Completion/Unix/Command/_iconv
index 190ed5f..82c2d32 100644
--- a/Completion/Unix/Command/_iconv
+++ b/Completion/Unix/Command/_iconv
@@ -1,37 +1,58 @@
#compdef iconv
local expl curcontext="$curcontext" state line ret=1
-local LOCPATH="${LOCPATH:-/usr/lib/nls/loc}"
-local -U codeset
-
-if _pick_variant gnu='(GNU|EGLIBC)' unix --version; then
-
- local exargs="--list -? --help --usage --version -V"
- _arguments -C -S -s \
- "(-f --from-code $exargs)"{-f+,--from-code=}'[specify code set of input file]:code set:->codeset' \
- "(-t --to-code $exargs)"{-t+,--to-code=}'[specify code set for output]:code set:->codeset' \
- '(- 1 -l --list)'{-l,--list}'[list all character code sets]' \
- "($exargs)-c[omit invalid characters from output]" \
- "(-o --output $exargs)"{-o+,--output=}'[specify output file]:output file:_files' \
- "(-s --silent --verbose $exargs)"{-s,--silent}'[suppress warnings]' \
- "(-s --silent $exargs)--verbose[print progress information]" \
- '(-)'{-\?,--help}'[display help information]' \
- '(-)--usage[display a short usage message]' \
- '(-)'{-V,--version}'[print program version]' \
- '1:input file:_files' && return 0
- if [[ $state = codeset ]]; then
- if compset -P '*[^/]/'; then
- _wanted option expl option compadd "$@" /TRANSLIT && ret=0
+if _pick_variant libiconv='GNU*libiconv' glibc='(GNU*libc|EGLIBC)' unix --version; then
+ local -a args
+ local exargs="-l --list -? --help --usage --version -V"
+
+ args=(
+ "(-f --from-code $exargs)"{-f+,--from-code=}'[specify code set of input file]:code set:->from_codeset'
+ "(-t --to-code $exargs)"{-t+,--to-code=}'[specify code set for output]:code set:->to_codeset'
+ '(- 1 -l --list)'{-l,--list}'[list all character code sets]'
+ "($exargs)-c[omit invalid characters from output]"
+ "(-s --silent --verbose $exargs)"{-s,--silent}'[suppress warnings]'
+ '(-)'{-\?,--help}'[display help information]'
+ '(-)--usage[display a short usage message]'
+ '(-)'{-V,--version}'[print program version]'
+ '1:input file:_files'
+ )
+
+ case $_cmd_variant[$service] in
+ (libiconv)
+ args=( ${(R)args:#(|\*)(|\(*\))-[V\?]*} ) # remove -V and -?
+ args+=(
+ '--byte-subst=[format for unconvertible bytes]:format string:'
+ '--widechar-subst=[format for unconvertible wide chars]:format string:'
+ '--unicode-subst=[format for unconvertible Unicode chars]:format string:'
+ )
+ ;;
+ (glibc)
+ args+=(
+ "(-o --output $exargs)"{-o+,--output=}'[specify output file]:output file:_files'
+ "(-s --silent $exargs)--verbose[print progress information]"
+ )
+ ;;
+ esac
+
+ _arguments -C -S -s : $args && return 0
+
+ if [[ $state = *_codeset ]]; then
+ # suffix is meaningfull only for output encoding
+ if [[ $state = to_codeset ]] && compset -P '*[^/]/'; then
+ _wanted suffix expl suffix compadd "$@" /TRANSLIT /IGNORE && ret=0
else
_wanted codesets expl 'code set' compadd "$@" \
- -M 'm:{a-zA-Z}={A-Za-z} r:|-=* r:|=*' \
- ${${${(f)"$(_call_program codesets iconv --list)"}## #}%//} && ret=0
+ -M 'm:{a-zA-Z}={A-Za-z} r:|-=* r:|=*' \
+ ${$(_call_program codesets iconv --list)%//} && ret=0
fi
fi
return ret
+
else
+ local LOCPATH="${LOCPATH:-/usr/lib/nls/loc}"
+ local -U codeset
_arguments -C \
'-f[specify code set of input file]:code set:->codeset' \
next reply other threads:[~2013-11-26 5:23 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-26 3:52 Jun T. [this message]
2013-12-09 8:55 ` Jun T.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5E95BB3E-EA71-4261-AC16-305A1068C3C9@kba.biglobe.ne.jp \
--to=takimoto-j@kba.biglobe.ne.jp \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).