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