about summary refs log tree commit diff
path: root/Completion/Unix/Command/_localedef
blob: 57637e3eca22cd14c46a56b1c4bcdd4389de5b1a (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
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
81
82
83
84
85
86
87
88
89
90
91
92
#compdef localedef

local curcontext="$curcontext" state line expl ret=1
typeset -A opt_args

if _pick_variant gnu='(Free Soft|GNU|GLIBC)' 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 debug 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