_eselect news function rewriten. NB: todo mark inside. Fixes #186

Signed-off-by: Vadim A. Misbakh-Soloviov <mva@mva.name>
This commit is contained in:
Vadim A. Misbakh-Soloviov 2013-11-12 01:00:44 +07:00
parent 918b318cc5
commit de603da79a
1 changed files with 53 additions and 15 deletions

View File

@ -46,7 +46,6 @@
#<app-admin/eselect-1.0.11>
#
_eselect_env() {
if (( $words[(I)(update)] )); then
_values 'update options' \
@ -75,7 +74,7 @@ _eselect_kernel () {
kernellist=(${${${(M)${(f)"$(eselect --no-color kernel list)"}## *}// \**/}//( \[*\] | \[*\] )/})
_values 'available kernel version' $kernellist[@] && return 0
fi
_values 'kenrel options' $stdopts[@] \
_values 'kernel options' $stdopts[@] \
'list[List available kernel symlink targets]' \
'show[Show the current kernel symlink]' \
'set[Set a new kernel symlink target]' && return 0
@ -147,6 +146,45 @@ _eselect_vi () {
'show[Show the current vi implementation]' \
'update[Automatically update the vi provider]' && return 0
}
_eselect_news() {
##
## TODO: Normal numeric sorting.
## I've spent all the day (12.11.2013) on trying to rewrite this
## function to normally sort (to DO NOT sort, actually) news,
## but it start to grow to very big size and going to be too
## complicated.
## So, I either need to help to do it normally, or 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
newslist=(${${${${${${${(M)${(f)"$(eselect --no-color news list)"}## *}// \**/}/ \[/}/\] ##/\[}/%/]}/ \[/ (}/\] /) })
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;
if (( $words[(I)(unread)] )); then
newslist+=( "all[Unread all news items]" )
fi
_values -w 'news' $newslist[@] && return 0
fi
}
_eselect() {
local globopts sedcmd modnames modopts
local stdopts
@ -169,10 +207,10 @@ _eselect () {
_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) ]]; then
if [[ "$words[2]" == (env|binutils|kernel|ctags|profile|fontconfig|opengl|vi|news) ]]; then
_eselect_$words[2] "$@"
else
modopts=(${${${(M)${(f)"$(eselect --no-color $words[2] usage)"}## *}// */}// /})
modopts=(${${${${(M)${(f)"$(eselect --no-color $words[2] usage)"}## *}// */}// /}// */})
_arguments -s \
"*:portage:_values 'eselect $words[2] options' \$modopts[@]" && return 0
fi
@ -180,7 +218,7 @@ _eselect () {
elif ((CURRENT >= 4)); then
if (( $words[(I)(--no-color|--no-colour)] )); then
if (( $modnames[(I)$words[3]] )); then
if [[ "$words[3]" == (env|binutils|kernel|ctags|profile|fontconfig|opengl|vi) ]]; then
if [[ "$words[3]" == (env|binutils|kernel|ctags|profile|fontconfig|opengl|vi|news) ]]; then
_eselect_$words[3] "$@"
else
modopts=(${${${${(M)${(f)"$(eselect --no-color $words[3] usage)"}## *}// */}// /}// *})
@ -190,7 +228,7 @@ _eselect () {
fi
else
if (( $modnames[(I)$words[2]] )); then
_eselect_$words[2] "$@"
(whence _eselect_$words[2] &>/dev/null) && _eselect_$words[2] "$@"
fi
fi
fi