]>
Commit | Line | Data |
---|---|---|
c4c12f13 | 1 | #compdef localectl |
7059062c | 2 | # SPDX-License-Identifier: LGPL-2.1+ |
c4c12f13 | 3 | |
c501ecd7 | 4 | (( $+functions[_localectl_set-locale] )) || |
c4c12f13 | 5 | _localectl_set-locale() { |
627a98d3 ZJS |
6 | local -a _locales locale_fields |
7 | locale_fields=(LANG LANGUAGE LC_CTYPE LC_NUMERIC LC_TIME \ | |
8 | LC_COLLATE LC_MONETARY LC_MESSAGES LC_PAPER \ | |
9 | LC_NAME LC_ADDRESS LC_TELEPHONE \ | |
10 | LC_MEASUREMENT LC_IDENTIFICATION) | |
11 | # LC_ALL is omitted on purpose | |
12 | ||
c4c12f13 WG |
13 | local expl suf |
14 | _locales=( ${(f)"$(_call_program locales "$service" list-locales)"} ) | |
627a98d3 | 15 | compset -P1 '*=' |
c4c12f13 WG |
16 | if [[ -prefix 1 *\= ]]; then |
17 | local conf=${PREFIX%%\=*} | |
c4c12f13 WG |
18 | _wanted locales expl "locales configs" \ |
19 | _combination localeconfs confs=$conf locales "$@" - | |
20 | else | |
627a98d3 | 21 | compadd -S '=' $locale_fields |
c4c12f13 WG |
22 | fi |
23 | } | |
24 | ||
c501ecd7 | 25 | (( $+functions[_localectl_set-keymap] )) || |
c4c12f13 WG |
26 | _localectl_set-keymap() { |
27 | local -a _keymaps | |
c4c12f13 | 28 | if (( CURRENT <= 3 )); then |
1ed77495 | 29 | _keymaps=( ${(f)"$(_call_program locales "$service" list-keymaps)"} ) |
c4c12f13 WG |
30 | _describe keymaps _keymaps |
31 | else | |
32 | _message "no more options" | |
33 | fi | |
34 | } | |
35 | ||
c501ecd7 | 36 | (( $+functions[_localectl_set-x11-keymap] )) || |
c4c12f13 WG |
37 | _localectl_set-x11-keymap() { |
38 | if (( $+commands[pkg-config] )); then | |
39 | local -a _file _layout _model _variant _options | |
40 | local _xorg_lst | |
41 | _xorg_lst=${"$($commands[pkg-config] xkeyboard-config --variable=xkb_base)"} | |
42 | _file=( ${(ps:\n\!:)"$(<$_xorg_lst/rules/xorg.lst)"} ) | |
b010a6a1 MP |
43 | _layout=( ${${${(M)${(f)_file[2]}:# *}# }%% *} ) |
44 | _model=( ${${${(M)${(f)_file[1]}:# *}# }%% *} ) | |
c4c12f13 WG |
45 | _variant=( ${${${(M)${(f)_file[3]}:# *}# }%% *} ) |
46 | _options=( ${${${(M)${(f)_file[4]}:# *}# }%% *} ) | |
47 | #_layout=( ${(f)"$( echo $_file[1] | awk '/^ / {print $1}' )"} ) | |
48 | #_model=( ${(f)"$(echo $_file[2] | awk '/^ / {print $1}')"} ) | |
49 | #_variant=( ${(f)"$(echo $_file[3] | awk '/^ / {print $1}')"} ) | |
50 | #_options=( ${(f)"$(echo ${_file[4]//:/\\:} | awk '/^ / {print $1}')"} ) | |
51 | ||
52 | case $CURRENT in | |
53 | 2) _describe layouts _layout ;; | |
54 | 3) _describe models _model;; | |
55 | 4) _describe variants _variant;; | |
56 | 5) _describe options _options;; | |
57 | *) _message "no more options" | |
58 | esac | |
59 | fi | |
60 | } | |
61 | ||
c501ecd7 | 62 | (( $+functions[_localectl_commands] )) || |
63 | _localectl_commands() { | |
c4c12f13 WG |
64 | local -a _localectl_cmds |
65 | _localectl_cmds=( | |
66 | 'status:Show current locale settings' | |
67 | 'set-locale:Set system locale' | |
68 | 'list-locales:Show known locales' | |
69 | 'set-keymap:Set virtual console keyboard mapping' | |
70 | 'list-keymaps:Show known virtual console keyboard mappings' | |
71 | 'set-x11-keymap:Set X11 keyboard mapping' | |
4433c995 DM |
72 | 'list-x11-keymap-models:Show known X11 keyboard mapping models' |
73 | 'list-x11-keymap-layouts:Show known X11 keyboard mapping layouts' | |
74 | 'list-x11-keymap-variants:Show known X11 keyboard mapping variants' | |
75 | 'list-x11-keymap-options:Show known X11 keyboard mapping options' | |
c4c12f13 WG |
76 | ) |
77 | if (( CURRENT == 1 )); then | |
78 | _describe -t commands 'localectl command' _localectl_cmds | |
79 | else | |
80 | local curcontext="$curcontext" | |
81 | cmd="${${_localectl_cmds[(r)$words[1]:*]%%:*}}" | |
82 | if (( $+functions[_localectl_$cmd] )); then | |
83 | _localectl_$cmd | |
84 | else | |
1ed77495 | 85 | _message "unknown localectl command: $words[1]" |
c4c12f13 WG |
86 | fi |
87 | fi | |
88 | } | |
89 | ||
c4c12f13 WG |
90 | _arguments \ |
91 | {-h,--help}'[Show this help]' \ | |
92 | '--version[Show package version]' \ | |
93 | "--no-convert[Don't convert keyboard mappings]" \ | |
94 | '--no-pager[Do not pipe output into a pager]' \ | |
95 | '--no-ask-password[Do not prompt for password]' \ | |
862f4963 | 96 | {-H+,--host=}'[Operate on remote host]:userathost:_sd_hosts_or_user_at_host' \ |
4433c995 | 97 | {-M+,--machine=}'[Operate on local container]:machine' \ |
c501ecd7 | 98 | '*::localectl commands:_localectl_commands' |