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