about summary refs log tree commit diff
path: root/Completion/X/_xmodmap
blob: 4e7a8bfc8e7d4fb8d507a37fc81592bd93587827 (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
#compdef xmodmap

local state line ret=1
typeset -A opt_args

_x_arguments \
  -{help,grammar,verbose,quiet} \
  '-n[only show what would be done]' \
  '*-e[specify expression]:expression:->expr' \
  '-pm[print modifier map]' \
  '-pk[print keymap table]' \
  '-pke[print keymap table as expressions]' \
  '-pp[print pointer map]' \
  ':X mapping file:_files' && ret=0

if [[ -n "$state" ]]; then
  local expl expr="${PREFIX##[ 	]#}" what suf

  if compset -P '[^ 	]##[ 	]##'; then
    case "$expr" in
    keycode*)
      if compset -P '*=[ 	]#'; then
        compset -P '*[ 	]'
        what=ksyms
      elif [[ "$expr" = *[\ \	]##[^\ \	]##[\ \	] ]]; then
        IPREFIX="${IPREFIX}${PREFIX}"
	PREFIX=''
	compadd -S ' ' '=' && ret=0
      else
        _message 'key code or `any'"'"
      fi
      ;;
    keysym*)
      if compset -P '*=[ 	]#'; then
        compset -P '*[ 	]'
        what=ksyms
      elif [[ "$expr" = *[\ \	]##[^\ \	]##[\ \	] ]]; then
        IPREFIX="${IPREFIX}${PREFIX}"
	PREFIX=''
	compadd -S ' ' '=' && ret=0
      else
        what=ksym-eq
      fi
      ;;
    clear*)
      what=mods
      ;;
    (add|remove)*)
      if compset -P '*[ 	]##'; then
        what=ksyms
      else
        what=mods-eq
      fi
      ;;
    pointer*)
      if compset -P '*=[ 	]#'; then
        compset -P '*[ 	]'
        _description expl 'button code'
        compadd "$expl[@]" -qS ' ' 1 2 3 4 5 default
        return
      else
        IPREFIX="${IPREFIX}${PREFIX}"
	PREFIX=''
	compadd -S ' ' '=' && ret=0
      fi
      ;;
    esac

    if [[ "$what" = *eq* ]]; then
      suf=(-S ' = ')
    elif [[ "$what" = *ksyms* ]]; then
      if [[ -n "$compstate[quote]" ]]; then
        suf=(-S "$compstate[quote] " -r "$compstate[quote] ")
      else
        suf=(-qS ' ')
      fi
    else
      suf=()
    fi

    [[ "$what" = *mods* ]] && _x_modifier "$suf[@]" && ret=0
    [[ "$what" = *ksym* ]] && _x_keysym "$suf[@]" && ret=0

  else
    _description expl command
    compadd "$expl[@]" -S ' ' keycode keysym clear add remove && ret=0
    compadd "$expl[@]" -S ' = ' pointer && ret=0
  fi
fi

return ret