about summary refs log tree commit diff
path: root/Completion/Unix/Command/_iconv
blob: 8e12e2107cb1929c9485d9ea1118ff651e84e1ec (plain) (blame)
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
#compdef iconv

local expl curcontext="$curcontext" state line codeset LOCPATH ret=1

if _pick_variant gnu=GNU 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)--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
      else
	_wanted codesets expl 'code set' compadd "$@" -M 'r:|-=* r:|=*' \
	    ${${${(f)"$(iconv --list|sed -n '/^$/,$ p')"}## #}%//} && ret=0
      fi
    fi
    
    return ret
else

  _arguments -C \
    '-f[specify code set of input file]:code set:->codeset' \
    '-t[specify code set for output]:code set:->codeset' \
    '1:file:_files' && return 0

    if [[ $state = codeset ]]; then
      if [[ -f /usr/lib/iconv/iconv_data ]]; then  # IRIX & Solaris
	codeset=( ${${(f)"$(</usr/lib/iconv/iconv_data)"}%%[[:blank:]]*} )
      elif [[ -d ${LOCPATH:=/usr/lib/nls/loc}/iconv ]]; then  # OSF
	codeset=( $LOCPATH/iconv/*(N:t) )
	codeset=( ${(j:_:s:_:)codeset} )
      else
	return 1
      fi
	
      _wanted codesets expl 'code set' compadd "$@" -a codeset
    fi

fi