about summary refs log tree commit diff
path: root/Completion/Unix/Command/_tr
blob: d55fab5ff93dc3bd299325fe7b6b1d17360554ce (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 tr

local curcontext="$curcontext" state line expl ret=1
local args variant
local -A descr
descr=(
  -c '[complement characters specified by first string]'
  -d '[delete specified characters from input]'
  -s '[squeeze repeated instances of character to a single instance]'
)

_pick_variant -r variant gnu=GNU $OSTYPE --version
case $variant in
  gnu)
    args=(
      '(-c -C --complement)'{-c,-C,--complement}"${descr[-c]}"
      '(-d --delete 2)'{-d,--delete}"${descr[-d]}"
      '(-s --squeeze-repeats)'{-s,--squeeze-repeats}"${descr[-s]}"
      '(- 1 2)--help[display help information]'
      '(- 1 2)--version[display version information]'
    )
  ;;
  darwin*|dragonfly*|*bsd*)
    args+=( "(-c)-C$descr[-c]" )
  ;|
  darwin*|dragonfly*|freebsd*)
    args+=( '-u[guarantee that output is unbuffered]' )
  ;|
  *)
    for k in c d s; do
      args+=( -$k$descr[$k] )
    done
  ;;
esac

_arguments -C -s $args \
  '1:character set:->chsets' \
  '2:character set:->chsets' && ret=0

if [[ -n $state ]]; then
  if compset -P '*\[:'; then
    _wanted characters expl 'character class' \
        compadd -S ":${${QIPREFIX:+]}:-\]}$compstate[quote] " \
	alnum alpha blank cntrl digit graph lower print punct space upper \
	xdigit && return
  elif compset -P '*\\'; then
    _describe -t characters character \
        '(\\\\:backslash a:alert b:backspace f:form\ feed n:new\ line r:return t:tab v:vertical\ tab)' -S '' && return
  fi
  _message -e characters 'character set'
fi

return ret