File indexing completed on 2024-05-05 05:39:29

0001 #compdef systemsettings kcmshell5 kcmshell6 kinfocenter
0002 
0003 # SPDX-FileCopyrightText: 2022 ivan tkachenko <me@ratijas.tk>
0004 #
0005 # SPDX-License-Identifier: GPL-2.0-or-later
0006 
0007 # standard stuff for `_arguments -C`
0008 local context state state_descr line
0009 typeset -A opt_args
0010 
0011 local ret=1 kcm_line kcm_name kcm_desc quantity
0012 local -a lines kcm_list kcmshell
0013 local -A kcm_assoc
0014 
0015 if [[ "$service" == "kcmshell5" || "$service" == "kcmshell6" ]]; then
0016   kcmshell=(
0017     '--caption=[Use a specific caption for the window]:caption:'
0018     '--icon=[Use a specific icon for the window]:icon:'
0019   )
0020   quantity='*'
0021   if [[ "$service" == "kcmshell6" ]]; then
0022     kcmshell+=(
0023       '--highlight[Show an indicator when settings have changed from their default value]'
0024     )
0025   fi
0026 else
0027   quantity='1'
0028 fi
0029 
0030 _arguments -C \
0031   $kcmshell \
0032   '(- *)--help[Displays help on commandline options.]' \
0033   '(- *)--list[List all possible modules]' \
0034   '--args=[Arguments for the module]:arguments:' \
0035   "$quantity:module:->kcm" \
0036   && ret=0
0037 
0038 case $state in
0039   kcm)
0040     lines=( ${(f)"$(_call_program kcm-list $service --list)"} )
0041     lines[1]=()  # first line is header, drop it
0042 
0043     kcm_assoc=()
0044     for kcm_line in $lines ; do
0045       # split at hypen into name and description, and strip whitespace
0046       kcm_name=${kcm_line%% *}
0047       kcm_desc=${kcm_line##*- }
0048       # skip already specified KCMs except for current word
0049       if (( $words[(Ie)$kcm_name] && $words[(Ie)$kcm_name] != $CURRENT )); then
0050         continue
0051       fi
0052       # some kcm names may get duplicates e.g. because of development setup,
0053       # store them in hash to automatically deduplicate
0054       kcm_assoc[$kcm_name]=$kcm_desc
0055     done
0056 
0057     kcm_list=()
0058     for kcm_name kcm_desc in ${(@kv)kcm_assoc} ; do  # iterate over array (@) of keys (k) and values (v)
0059       kcm_desc=${kcm_desc//:/\\:}  # espace double colons for _describe
0060       kcm_list+=( "${kcm_name}:${kcm_desc}" )
0061     done
0062 
0063     _describe -t kcm 'settings module' kcm_list && ret=0
0064     ;;
0065 esac
0066 
0067 return $ret