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