aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/_eselect')
-rw-r--r--src/_eselect363
1 files changed, 198 insertions, 165 deletions
diff --git a/src/_eselect b/src/_eselect
index 46b8477..77b9fd6 100644
--- a/src/_eselect
+++ b/src/_eselect
@@ -1,199 +1,232 @@
-#compdef eselect
-
-common_values=(
- "help[Display help text]"
- "usage[Display usage information]"
- "version[Display version information]"
-)
-
-_eselect_env () {
- if (( $words[(I)(update)] )); then
- _values "update options" \
- "makelinks[force updating of links]" \
- "noldconfig[Do not alter the ld.so cache or configuration]" && return 0
+#compdef eselect kernel-config profile-config rc-config
+
+_eselect_parse_generic() {
+ local -a mod_std mod_extra
+ local -a eselect_args
+ local mod_cur eselect_descr
+ local mod descr etype
+
+ eselect_args=($@)
+ if [[ $1 == "modules" ]] ; then
+ eselect_args=($1 usage)
fi
- _values "env options" $common_values \
- 'update[Collect environment variables from all scripts in /etc/env.d/]' && return 0
-}
+ mod_cur="mod_extra"
+ eselect_descr="$(LANG=C COLUMNS=100 eselect --colour=no ${eselect_args[@]} 2> /dev/null)"
+
+ while IFS="" read -r helpdesc ; do
+ case "$helpdesc" in
+ ("Built-in modules:"|"Standard actions:"))
+ mod_cur="mod_std"
+ ;;
+ ("Extra modules:"|"Extra actions:"))
+ mod_cur="mod_extra"
+ ;;
+ esac
+
+ if [[ "$helpdesc" =~ '^ [A-Za-z]' ]] ; then
+ echo "$helpdesc" | read mod descr
+ descr="$(echo "$descr" | sed -r -e 's/.*\s\s\s+//')"
+ set -A $mod_cur ${(P)mod_cur} ${mod}:${(q)descr}
+ fi
+ done <<< "$eselect_descr"
-_eselect_binutils () {
- local binutilslist
- if (( $words[(I)(set)] )); then
- binutilslist=(${(f)"$(eselect --brief --color=no binutils list)"})
- _values "available binutils version" $binutilslist[@] && return 0
+ if [[ -z "${eselect_args[@]}" ]] ; then
+ etype="modules"
+ else
+ etype="actions"
fi
- _values "binutils options" $common_values \
- "list[List all installed version of binutils]" \
- "show[Print the currently active binutils version]" \
- "set[Activate one of the installed binutils]" && return 0
-}
-_eselect_kernel () {
- local kernellist
- if (( $words[(I)(set)] )); then
- kernellist=(${(f)"$(eselect --brief --color=no kernel list)"})
- _values "available kernel version" $kernellist[@] && return 0
+ if [[ -z "${mod_extra}" && -z "${mod_std}" ]] ; then
+ _nothing
+ else
+ _describe -t eselect_extra -V "eselect extra $etype" mod_extra
+ _describe -t eselect_standard -V "eselect standard $etype" mod_std
fi
- _values "kernel options" $common_values \
- "list[List available kernel symlink targets]" \
- "show[Show the current kernel symlink]" \
- "set[Set a new kernel symlink target]" && return 0
}
-_eselect_ctags () {
- local ctagslist
- if (( $words[(I)(set)] )); then
- ctagslist=(${(f)"$(eselect --brief --color=no ctags list)"})
- _values "available ctags version" $ctagslist[@] && return 0
+_eselect_parse_action_list() {
+ local eselect_list
+ local idx descr
+ local arr_items_selected=$2
+ local arr_items_unselected=$3
+
+ eselect_list="$(LANG=C COLUMNS=100 eselect --colour=no $1 list 2> /dev/null)"
+ while IFS="" read -r ele ; do
+ echo "$ele" | read idx descr
+ idx=${idx#*\[}
+ idx=${idx%\]*}
+ if [[ "$idx" =~ '^[0-9]+$' ]]; then
+ local stripped_descr="${descr% *\**}"
+ if [[ "${stripped_descr}" != "${descr}" ]] ; then
+ set -A $arr_items_selected ${(P)arr_items_selected} "$idx:${(q)descr}"
+ else
+ set -A $arr_items_unselected ${(P)arr_items_unselected} "$idx:${(q)descr}"
+ fi
+ fi
+ done <<< "$eselect_list"
+}
+
+_eselect_module_action() {
+ if (( $+functions[_eselect_${1}_action] )) ; then
+ _eselect_${1}_action
+ else
+ _eselect_parse_generic ${1}
fi
- _values "ctags options" $common_values \
- "list[List available ctags symlink targets]" \
- "show[Show the current target of the ctags symlink]" \
- "update[Automatically update the ctags symlink]" \
- "set[Set a new ctags symlink target]" && return 0
}
-_eselect_profile () {
- local profilelist
- if (( $words[(I)(set)] )); then
- profilelist=(${${(f)"$(eselect --brief --color=no profile list)"}/:/\\:})
- _values -w "available profiles" $profilelist[@] \
- "--force[Forcibly set the symlink]" && return 0
+_eselect_complete_action() {
+ local actionname=$(_eselect_get_module)
+ if (( $+functions[_eselect_complete_${actionname}_action] )) ; then
+ _eselect_complete_${actionname}_action
+ else
+ _eselect_complete_action_generic ${actionname}
fi
- _values "profile options" $common_values \
- "list[List available profile symlink targets]" \
- "show[Show the current make.profile symlink]" \
- "set[Set a new profile symlink target]" && return 0
}
-_eselect_fontconfig () {
- local fclistenabled fclistdisabled
- if (( $words[(I)(enable)] )); then
- fclistdisabled=(${${${${(M)${(f)"$(eselect --color=no fontconfig list)"}## *}#*\*}// \**/}//( \[*\] | \[*\] )/})
- _values -w ".conf to enable" $fclistdisabled[@] && return 0
- elif (( $words[(I)(disable)] )); then
- fclistenabled=(${${${(M)${(M)${(f)"$(eselect --color=no fontconfig list)"}## *}#*\*}// \**/}//( \[*\] | \[*\] )/})
- _values -w ".conf to disable" $fclistenabled[@] && return 0
+_eselect_get_module() {
+ if [[ $service == "eselect" ]] ; then
+ echo $line[1]
+ else
+ echo ${service%-config}
fi
- _values "fontconfig options" $common_values \
- "list[List available fontconfig .conf files]" \
- "disable[Disable specified fontconfig .conf file(s)]" \
- "enable[Enable specified fontconfig .conf file(s)]" && return 0
}
-_eselect_opengl () {
- local opengllist
- if (( $words[(I)(set)] )); then
- opengllist=(${(f)"$(eselect --brief --color=no opengl list)"})
- _values -w "opengl implementations and options" $opengllist[@] \
- "--use-old[If an implementation is already set, use that one instead]" \
- "--prefix[Set the source prefix]:path:_files -/" \
- "--dst-prefix[Set the destination prefix]:path:_files -/" \
- "--ignore-missing[Ignore missing files when setting a new implementation]" && return 0
+_eselect_action_index() {
+ if [[ $service == "eselect" ]] ; then
+ echo 2
+ else
+ echo 1
fi
- _values "opengl options" $common_values \
- "list[List the available OpenGL implementations]" \
- "set[Select the OpenGL implementation]" \
- "show[Print the current OpenGL implementation]" && return 0
+}
+_eselect_get_action () {
+ echo ${line[$(_eselect_action_index)]}
+}
+
+_eselect_action() {
+ _eselect_module_action $(_eselect_get_module)
+}
+
+_eselect_module() {
+ _eselect_parse_generic
}
-_eselect_vi () {
- local vilist
- if (( $words[(I)(set)] )); then
- vilist=(${(f)"$(eselect --brief --color=no vi list)"})
- _values -w "vi implementation" $vilist[@] && return 0
- elif (( $words[(I)(update)] )); then
- _values -w "option" "--if-unset[Do not override existing implementation]" && return 0
+_eselect_complete_action_generic() {
+ local -a sel_items
+ local -a unsel_items
+
+ if (( $NORMARG + $(_eselect_action_index) == $CURRENT )) ; then
+ case "$(_eselect_get_action)" in
+ ("set"|"enable"))
+ _eselect_parse_action_list $1 sel_items unsel_items
+ if (( $#unsel_items + $#sel_items > 0 )) ; then
+ _describe -t eselect_sel -V 'eselect items' unsel_items
+ if (( $#unsel_items + $#sel_items < 10 )) ; then
+ _describe -t eselect_unsel -V 'eselect already selected items' sel_items
+ fi
+ return 0
+ fi
+ ;;
+ ("remove"|"disable"))
+ _eselect_parse_action_list $1 sel_items unsel_items
+ if [[ -n "${sel_items[@]}" ]] ; then
+ _describe -V 'eselect items' sel_items
+ return 0
+ fi
+ ;;
+ esac
fi
- _values "vi options" $common_values \
- "list[List available vi implementations]" \
- "set[Set a new vi implementation provider]" \
- "show[Show the current vi implementation]" \
- "update[Automatically update the vi provider]"
+
+ _nothing
}
-_eselect_news() {
-
- ## TODO: Normal numeric sorting.
- ## I've spent many time on trying to rewrite this
- ## function to normally sort (to DO NOT sort, actually) items,
- ## but it growing bigger and bigger and going to be too complicated.
- ## So, I (mva) either need to help to make it in the "right way".
- ## Or, maybe, to completely rewrite this compdef.
-
- local -a newslist;
- if ((CURRENT == 3)); then
- _values 'news options' $stdopts[@] \
- 'list[List news items]' \
- 'count[Display number of news items]' \
- 'purge[Purge read news]' \
- 'read[Read news items]' \
- 'unread[Mark read news items as unread again]' && return 0
- elif ((CURRENT == 4)); then
- if (( $words[(I)(count)] )); then
- _values -w 'news' 'new[Count only new news items]' 'all[Count all news items]' && return 0
- fi
+# custom completions:
+(( $+functions[_eselect_complete_news_action] )) || _eselect_complete_news_action() {
+ local -a items
- newslist=(${${${${${${${(M)${(f)"$(eselect --color=no news list)"}## *}// \**/}/ \[/}/\] ##/\[}/%/]}/ \[/ (}/\] /) })
+ case "$(_eselect_get_action)" in
+ ("read"|"unread"))
+ local -a extra_items=('all:Read all news items')
+ if [[ $(_eselect_get_action) == "read" ]] ; then
+ extra_items=('new:Read unread news items (default)' "${extra_items[@]}")
+ fi
+ _eselect_parse_action_list news items items
- if (( $words[(I)(read)] )); then
- newslist+=( "new[Read unread news items (default)]" "all[Read all news items]" "--mbox[Output in mbox format]" "--quiet[Suppress output, only change status]" "--raw[Output in raw format]" )
- fi;
+ items=(${(q)extra_items[@]} ${(Oa)items})
+ if [[ -n "${items[@]}" ]] ; then
+ _describe -V 'eselect items' items
+ return 0
+ fi
+ ;;
+ esac
- if (( $words[(I)(unread)] )); then
- newslist+=( "all[Unread all news items]" )
- fi
+ _nothing
+}
- _values -w 'news' $newslist[@] && return 0
+(( $+functions[_eselect_complete_kernel_action] )) || _eselect_complete_kernel_action() {
+ local -a items
+
+ if (( $NORMARG + $(_eselect_action_index) == $CURRENT )) ; then
+ case "$(_eselect_get_action)" in
+ "set")
+ for k in ${(@f)$(eselect --colour=no --brief kernel list)} ; do
+ items+=${k#linux-}
+ done
+ local -a expl=(-P linux-)
+ compadd -V 'eselect kernel' -P linux- ${items[@]}
+ return 0
+ ;;
+ esac
fi
+
+ _nothing
}
-_eselect () {
- local globopts modnames modopts
-
- globopts=(
- "--brief[Make output shorter]"
- "--colour=no[Disable coloured output]"
- "--color=no[Disable coloured output]"
- )
- modnames=(${${${(M)${(f)"$(eselect --brief --color=no modules list)"}## *}// */}// /})
-
- if ((CURRENT == 2)); then
- _arguments -s \
- "$globopts[@]" \
- "*:portage:_values 'eselect modules' \$modnames[@]" && return 0
- elif ((CURRENT == 3)); then
- if [[ $words[2] == --colour=no || $words[2] == --color=no ]]; then
- _arguments -s \
- "*:portage:_values 'eselect modules' \$modnames[@]" && return 0
- elif (( $modnames[(I)$words[2]] )); then
- if [[ "$words[2]" == (env|binutils|kernel|ctags|profile|fontconfig|opengl|vi|news) ]]; then
- _eselect_$words[2] "$@"
- else
- modopts=(${${${(M)${(f)"$(eselect --brief --color=no $words[2] usage)"}## *}// */}// /})
- _arguments -s \
- "*:portage:_values 'eselect $words[2] options' \$modopts[@]" && return 0
- fi
- fi
- elif ((CURRENT >= 4)); then
- if (( $words[(I)(--color=no|--colour=no)] )); then
- if (( $modnames[(I)$words[3]] )); then
- if [[ "$words[3]" == (env|binutils|kernel|ctags|profile|fontconfig|opengl|vi|news) ]]; then
- _eselect_$words[3] "$@"
- else
- modopts=(${${${${(M)${(f)"$(eselect --brief --color=no $words[3] usage)"}## *}// */}// /}// *})
- _arguments -s \
- "*:portage:_values 'eselect $words[3] options' \$modopts[@]" && return 0
- fi
- fi
- else
- if (( $modnames[(I)$words[2]] )); then
- (( $+functions[_eselect_$words[2]] )) && _eselect_$words[2] "$@"
- fi
- fi
+(( $+functions[_eselect_complete_profile_action] )) || _eselect_complete_profile_action() {
+ if (( $NORMARG + $(_eselect_action_index) == $CURRENT )) ; then
+ case "$(_eselect_get_action)" in
+ "set")
+ _values 'eselect profiles' $(eselect --colour=no --brief profile list)
+ return 0
+ ;;
+ esac
fi
+
+ _nothing
+}
+
+(( $+functions[_eselect_complete_timezone_action] )) || _eselect_complete_timezone_action() {
+ if (( $NORMARG + $(_eselect_action_index) == $CURRENT )) ; then
+ case "$(_eselect_get_action)" in
+ "set")
+ _multi_parts / "($(eselect --colour=no --brief timezone list))"
+ return 0
+ ;;
+ esac
+ fi
+
+ _nothing
+}
+
+eselect_comp() {
+ integer NORMARG
+
+ case "$service" in
+ eselect)
+ _arguments -A '-*' -n \
+ '--brief[Make output shorter]' \
+ '(--colour --color)'--colo{,u}r='[Enable or disable colour output]:colour:(yes no)' \
+ '1:eselect_module:_eselect_module' \
+ '2:eselect_action:_eselect_action' \
+ '*:eselect_complete_action:_eselect_complete_action'
+ ;;
+ *-config)
+ _arguments -n \
+ "1:action:_eselect_action" \
+ '*:eselect_complete_action:_eselect_complete_action'
+ ;;
+ esac
}
-_eselect "$@"
+eselect_comp "$@"
# vim: set et sw=2 ts=2 ft=zsh: