1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
# (C) 2010-2013 magicant
# Completion script for the "iconv" command.
# Supports POSIX 2008, GNU libc 2.12.1, GNU libiconv 1.13, NetBSD 5.0,
# SunOS 5.10, HP-UX 11i v3.
function completion/iconv {
case $("${WORDS[1]}" --version 2>/dev/null) in
(*'GNU libc'*) typeset type=glibc ;;
(*'GNU libiconv'*) typeset type=glibiconv ;;
(*) typeset type="$(uname 2>/dev/null)" ;;
esac
case $type in
(glibc|glibiconv) typeset long=true ;;
(*) typeset long= ;;
esac
typeset OPTIONS ARGOPT PREFIX
OPTIONS=( #>#
"c; discard unconvertible characters"
"f: ${long:+--from-code:}; specify the input encoding"
"l ${long:+--list}; print all supported encodings"
"s ${long:+--silent}; suppress warnings about unconvertible characters"
"t: ${long:+--to-code:}; specify the output encoding"
) #<#
case $type in
(glibc)
OPTIONS=("$OPTIONS" #>#
"o: --output:; specify the file to output"
"? --help; print help"
"--verbose; print progress info"
"V --version; print version info"
) #<#
;;
(glibiconv)
OPTIONS=("$OPTIONS" #>#
"--unicode-subst:; specify a format to substitute unconvertible Unicode characters with"
"--byte-subst:; specify a format to substitute unconvertible bytes with"
"--widechar-subst:; specify a format to substitute invalid wide characters with"
) #<#
;;
esac
command -f completion//parseoptions ${long:+-es}
case $ARGOPT in
(-)
command -f completion//completeoptions
;;
([ft]|--from-code|--to-code)
command -f completion/iconv::compenc "${WORDS[1]}"
;;
(*)
complete -P "$PREFIX" -f
;;
esac
}
function completion/iconv::compenc {
typeset iconv="${1-iconv}"
case $("$iconv" --version 2>/dev/null) in
(*'GNU libc'*) typeset type=glibc ;;
(*'GNU libiconv'*) typeset type=glibiconv ;;
(*) typeset type="$(uname 2>/dev/null)" ;;
esac
# POSIX does not specify the format of `iconv -l' output.
# We support GNU libc and libiconv for now.
case $type in (glibc|glibiconv)
complete -P "$PREFIX" -- $("$iconv" -l 2>/dev/null)
esac
}
# vim: set ft=sh ts=8 sts=8 sw=8 et:
|