_localectl revision 627a98d39844a1ac10fde1f72cf18b4f08be4990
3802a3d3d7af51ddff31943d5514382f01265770Lennart Poettering#compdef localectl
12b42c76672a66c2d4ea7212c14f8f1b5a62b78dTom Gundersen_localectl_set-locale() {
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek local -a _locales locale_fields
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek locale_fields=(LANG LANGUAGE LC_CTYPE LC_NUMERIC LC_TIME \
5de0ccffcc4a5a946102a14e0b0e681d964e3225Zbigniew Jędrzejewski-Szmek LC_COLLATE LC_MONETARY LC_MESSAGES LC_PAPER \
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek LC_NAME LC_ADDRESS LC_TELEPHONE \
5de0ccffcc4a5a946102a14e0b0e681d964e3225Zbigniew Jędrzejewski-Szmek LC_MEASUREMENT LC_IDENTIFICATION)
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek # LC_ALL is omitted on purpose
5de0ccffcc4a5a946102a14e0b0e681d964e3225Zbigniew Jędrzejewski-Szmek _locales=( ${(f)"$(_call_program locales "$service" list-locales)"} )
5de0ccffcc4a5a946102a14e0b0e681d964e3225Zbigniew Jędrzejewski-Szmek compset -P1 '*='
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek if [[ -prefix 1 *\= ]]; then
5de0ccffcc4a5a946102a14e0b0e681d964e3225Zbigniew Jędrzejewski-Szmek local conf=${PREFIX%%\=*}
5de0ccffcc4a5a946102a14e0b0e681d964e3225Zbigniew Jędrzejewski-Szmek _wanted locales expl "locales configs" \
5de0ccffcc4a5a946102a14e0b0e681d964e3225Zbigniew Jędrzejewski-Szmek _combination localeconfs confs=$conf locales "$@" -
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek compadd -S '=' $locale_fields
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek_localectl_set-keymap() {
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek local -a _keymaps
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek _keymaps=( ${(f)"$(_call_program locales "$service" list-keymaps)"} )
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek if (( CURRENT <= 3 )); then
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek _describe keymaps _keymaps
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek _message "no more options"
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek_localectl_set-x11-keymap() {
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek if (( $+commands[pkg-config] )); then
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek local -a _file _layout _model _variant _options
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek _xorg_lst=${"$($commands[pkg-config] xkeyboard-config --variable=xkb_base)"}
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek _file=( ${(ps:\n\!:)"$(<$_xorg_lst/rules/xorg.lst)"} )
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek _layout=( ${${${(M)${(f)_file[1]}:# *}# }%% *} )
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek _model=( ${${${(M)${(f)_file[2]}:# *}# }%% *} )
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek _variant=( ${${${(M)${(f)_file[3]}:# *}# }%% *} )
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek _options=( ${${${(M)${(f)_file[4]}:# *}# }%% *} )
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek #_layout=( ${(f)"$( echo $_file[1] | awk '/^ / {print $1}' )"} )
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek #_model=( ${(f)"$(echo $_file[2] | awk '/^ / {print $1}')"} )
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek #_variant=( ${(f)"$(echo $_file[3] | awk '/^ / {print $1}')"} )
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek #_options=( ${(f)"$(echo ${_file[4]//:/\\:} | awk '/^ / {print $1}')"} )
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek case $CURRENT in
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek 2) _describe layouts _layout ;;
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek 3) _describe models _model;;
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek 4) _describe variants _variant;;
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek 5) _describe options _options;;
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek *) _message "no more options"
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek_localectl_command() {
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek local -a _localectl_cmds
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek _localectl_cmds=(
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek 'status:Show current locale settings'
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek 'set-locale:Set system locale'
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek 'list-locales:Show known locales'
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek 'set-keymap:Set virtual console keyboard mapping'
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek 'list-keymaps:Show known virtual console keyboard mappings'
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek 'set-x11-keymap:Set X11 keyboard mapping'
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek if (( CURRENT == 1 )); then
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek _describe -t commands 'localectl command' _localectl_cmds
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek local curcontext="$curcontext"
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek cmd="${${_localectl_cmds[(r)$words[1]:*]%%:*}}"
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek if (( $+functions[_localectl_$cmd] )); then
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek _message "no more options"
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek {-h,--help}'[Show this help]' \
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek '--version[Show package version]' \
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek "--no-convert[Don't convert keyboard mappings]" \
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek '--no-pager[Do not pipe output into a pager]' \
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek '--no-ask-password[Do not prompt for password]' \
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek {-H+,--host=}'[Operate on remote host]:userathost:_sd_hosts_or_user_at_host' \
330427e271c37400f091bf4570b5d8fa96574d36Zbigniew Jędrzejewski-Szmek '*::localectl commands:_localectl_command'