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