|
| 1 | +#compdef xkbcli -P xkbcli-* |
| 2 | + |
| 3 | +local context state state_descr line |
| 4 | +typeset -A opt_args |
| 5 | +local expl |
| 6 | + |
| 7 | +_xkbcli_commands() { |
| 8 | + local -a commands=( |
| 9 | + 'list:list available rules, models, layouts, variants and options' |
| 10 | + 'interactive:interactive debugger for XKB keymaps' |
| 11 | + 'interactive-wayland:interactive debugger for XKB keymaps for Wayland' |
| 12 | + 'interactive-x11:interactive debugger for XKB keymaps for X11' |
| 13 | + 'interactive-evdev:interactive debugger for XKB keymaps for evdev' |
| 14 | + 'dump-keymap:dump a XKB keymap from a Wayland or X11 compositor' |
| 15 | + 'dump-keymap-wayland:dump a XKB keymap from a Wayland compositor' |
| 16 | + 'dump-keymap-x11:dump a XKB keymap from an X server' |
| 17 | + 'compile-keymap:compile an XKB keymap' |
| 18 | + 'compile-compose:compile a Compose file' |
| 19 | + 'how-to-type:print key sequences to type a Unicode codepoint' |
| 20 | + ) |
| 21 | + |
| 22 | + _describe xkbcli-command commands |
| 23 | +} |
| 24 | + |
| 25 | +local -a rmlvo_opts_common=( |
| 26 | + '--rules=[the XKB ruleset]:rules:()' |
| 27 | + '--model=[the XKB model]:model:()' |
| 28 | + '--layout=[the XKB layout]:layout:()' |
| 29 | + '--variant=[the XKB variant]:variant:()' |
| 30 | + '--options=[the XKB options]:options:()' |
| 31 | + '--enable-environment-names[set the default RMLVO values from the environment]' |
| 32 | +) |
| 33 | + |
| 34 | +_xkbcli-list() { |
| 35 | + _arguments -S : \ |
| 36 | + '(-v --verbose)'{-v,--verbose}'[increase verbosity]' \ |
| 37 | + '--help[print a help message and exit]' \ |
| 38 | + '--ruleset=[load a ruleset]' \ |
| 39 | + '--skip-default-paths[do not load the default XKB paths]' \ |
| 40 | + '--load-exotic[load the exotic (extra) rulesets]' \ |
| 41 | + '*:xkb base directory:_files -/' |
| 42 | +} |
| 43 | + |
| 44 | +_xkbcli-interactive() { |
| 45 | + _arguments -S : \ |
| 46 | + '--verbose[enable verbose debugging output]' \ |
| 47 | + '--help[print a help message and exit]' \ |
| 48 | + '(-1 --uniline --multiline)--multiline[enable multiline event output]' \ |
| 49 | + '(-1 --uniline --multiline)'{-1,--uniline}'[enable uniline event output]' \ |
| 50 | + '(--local-state)--keymap=[use the given keymap instead of the compositor keymap]:keymap:_files' \ |
| 51 | + '--local-state[enable local state handling and ignore modifiers/layouts]' \ |
| 52 | + '--enable-compose[enable Compose]' \ |
| 53 | + '--format=[use the given keymap format]:xkb format:(v1 v2)' |
| 54 | +} |
| 55 | + |
| 56 | +_xkbcli-interactive-evdev() { |
| 57 | + _arguments -S : \ |
| 58 | + '--help[print a help message and exit]' \ |
| 59 | + '--format=[use the given keymap format]:xkb format:(v1 v2)' \ |
| 60 | + '--verbose[enable verbose debugging output]' \ |
| 61 | + '(-1 --uniline --multiline)'{-1,--uniline}'[enable uniline event output]' \ |
| 62 | + '(-1 --uniline --multiline)--multiline[enable multiline event output]' \ |
| 63 | + '--short[shorter event output]' \ |
| 64 | + '--report-state-changes[report changes to the state]' \ |
| 65 | + '--enable-compose[enable Compose]' \ |
| 66 | + '--consumed-mode=[select the consumed modifiers mode]:mode:(xkb|gtk)' \ |
| 67 | + '--without-x11-offset[do not add X11 keycode offset]' \ |
| 68 | + "$rmlvo_opts_common[@]" |
| 69 | +} |
| 70 | + |
| 71 | +_xkbcli-dump-keymap() { |
| 72 | + _arguments -S : \ |
| 73 | + '--verbose[enable verbose debugging output]' \ |
| 74 | + '--help[print a help message and exit]' \ |
| 75 | + '(--format)--input-format=[use the given input keymap format]:xkb format:(v1 v2)' \ |
| 76 | + '(--format)--output-format=[use the given output keymap format]:xkb format:(v1 v2)' \ |
| 77 | + '(--input-format --output-format)--format=[use the given keymap format for input and output]:xkb format:(v1 v2)' \ |
| 78 | + '--no-pretty[do not pretty preint when serializing a keymap]' \ |
| 79 | + '--drop-unused[disable unused bits serialization]' \ |
| 80 | + '--raw[dump raw keymap without parsing it]' |
| 81 | +} |
| 82 | + |
| 83 | + |
| 84 | +_xkbcli-compile-keymap() { |
| 85 | + _arguments -S : \ |
| 86 | + '--help[print a help message and exit]' \ |
| 87 | + '--verbose[enable verbose debugging output]' \ |
| 88 | + '--test[test compilation but do not print the keymap]' \ |
| 89 | + + input \ |
| 90 | + '*--include[add the given path to the include path list]' \ |
| 91 | + '--include-defaults[add the default set of include directories]' \ |
| 92 | + '(--format)--input-format=[the keymap format to use for parsing]:xkb format:(v1 v2)' \ |
| 93 | + '(--format)--output-format=[the keymap format to use for serializing]:xkb format:(v1 v2)' \ |
| 94 | + '(--input-format --output-format)--format=[the keymap format to use for parsing and serializing]:xkb format:(v1 v2)' \ |
| 95 | + '--no-pretty[do not pretty preint when serializing a keymap]' \ |
| 96 | + '--drop-unused[disable unused bits serialization]' \ |
| 97 | + '--keymap=[use the given keymap file]:keymap:_files' \ |
| 98 | + '--from-xkb=[use the given XKB file]:XKB keymap:_files' \ |
| 99 | + "$rmlvo_opts_common[@]" \ |
| 100 | + + '(output)' \ |
| 101 | + '--kccgst[print a keymap in KcCGST format]' \ |
| 102 | + '--kccgst-yaml[print a KcCGST keymap in YAML format]' \ |
| 103 | + '--rmlvo[print the full RMLVO in YAML format]' \ |
| 104 | + '--modmaps[print the real and virtual key modmaps in YAML format]' |
| 105 | +} |
| 106 | + |
| 107 | +_xkbcli-compile-compose() { |
| 108 | + _arguments -S : \ |
| 109 | + '--help[print a help message and exit]' \ |
| 110 | + '--verbose[enable verbose debugging output]' \ |
| 111 | + '--test[test compilation but do not print the Compose file]' \ |
| 112 | + '--locale=[use the specified locale]:locale:_locales' |
| 113 | +} |
| 114 | + |
| 115 | +_xkbcli-keysyms() { |
| 116 | + local include="/usr/include/xkbcommon/xkbcommon-keysyms.h" |
| 117 | + local -Ua keysyms=(${(@f)"$(_call_program -l keysym grep -Pwo 'XKB_KEY_\\K\\w+' $include)"}) |
| 118 | + _wanted keysym expl 'keysym' compadd -a "$@" - keysyms |
| 119 | +} |
| 120 | + |
| 121 | +_xkbcli-how-to-type() { |
| 122 | + local context state state_descr line |
| 123 | + typeset -A opt_args |
| 124 | + |
| 125 | + local ret=1 |
| 126 | + _arguments -S : \ |
| 127 | + '--help[print a help message and exit]' \ |
| 128 | + '--verbose[enable verbose debugging output]' \ |
| 129 | + '--keysym[treat the argument only as a keysym]' \ |
| 130 | + '--disable-compose[disable Compose support]' \ |
| 131 | + + xkb \ |
| 132 | + '--format=[the keymap format to use]' \ |
| 133 | + '--keymap=[the keymap file to load]:xkb keymap:_files' \ |
| 134 | + "$rmlvo_opts_common[@]" \ |
| 135 | + ': :->key' && ret=0 |
| 136 | + |
| 137 | + case $state in |
| 138 | + key) |
| 139 | + if (( $+opt_args[--keysym] )); then |
| 140 | + _xkbcli-keysyms && ret=0 |
| 141 | + else |
| 142 | + _alternative \ |
| 143 | + 'character:character:()' \ |
| 144 | + 'codepoint:codepoint:()' \ |
| 145 | + 'keysym:keysym:_xkbcli-keysyms' && ret=0 |
| 146 | + fi |
| 147 | + ;; |
| 148 | + esac |
| 149 | + return ret |
| 150 | +} |
| 151 | + |
| 152 | +local ret=1 |
| 153 | +case $service in |
| 154 | + xkbcli-interative-(wayland|x11)) |
| 155 | + _call_function ret _xkbcli-interactive && ret=0 |
| 156 | + return ret |
| 157 | + ;; |
| 158 | + xkbcli-dump-keymap-(wayland|x11)) |
| 159 | + _call_function ret _xkbcli-dump-keymap && ret=0 |
| 160 | + return ret |
| 161 | + ;; |
| 162 | + xkbcli-*) |
| 163 | + _call_function ret "_$service" |
| 164 | + return ret |
| 165 | + ;; |
| 166 | + xkbcli) |
| 167 | + _arguments -S : \ |
| 168 | + '(-)'{-h,--help}'[show a help message and exit]' \ |
| 169 | + '(-)'{-V,--version}'[show version info and exit]' \ |
| 170 | + '(-): :->command' \ |
| 171 | + '(-)*:: :->option-or-argument' && ret=0 |
| 172 | + ;; |
| 173 | +esac |
| 174 | + |
| 175 | +case $state in |
| 176 | + command) |
| 177 | + _xkbcli_commands && ret=0 |
| 178 | + ;; |
| 179 | + option-or-argument) |
| 180 | + local curcontext=${curcontext%:*:*}:xkbcli-$words[1]: |
| 181 | + case $words[1] in |
| 182 | + list) |
| 183 | + _xkbcli-list && ret=0 ;; |
| 184 | + interactive(|-wayland|-x11)) |
| 185 | + _xkbcli-interactive && ret=0 ;; |
| 186 | + interactive-evdev) |
| 187 | + _xkbcli-interactive-evdev && ret=0 ;; |
| 188 | + dump-keymap(|-wayland|-x11)) |
| 189 | + _xkbcli-dump-keymap && ret=0 ;; |
| 190 | + compile-keymap) |
| 191 | + _xkbcli-compile-keymap && ret=0 ;; |
| 192 | + compile-compose) |
| 193 | + _xkbcli-compile-compose && ret=0 ;; |
| 194 | + how-to-type) |
| 195 | + _xkbcli-how-to-type && ret=0 ;; |
| 196 | + *) |
| 197 | + _message "unknown $service command ${(qq)words[1]}" |
| 198 | + ;; |
| 199 | + esac |
| 200 | + ;; |
| 201 | +esac |
| 202 | +return ret |
0 commit comments