First Last Prev Next    No search results available      Search page      Enter new bug
Bug#: 33130
Alias:
Product:
Component:
Status: RESOLVED
Resolution: FIXED
Assigned To: Mamoru KOMACHI (RETIRED) <usata@gentoo.org>
Hardware:
OS:
Version:
Priority:
Severity:
Reporter: Bapt <baptiste.daroussin@gmail.com>
Add CC:
CC:
URL:
Summary:
Status Whiteboard:
Keywords:

Filename Description Type Creator Created Size Actions
_portage the completion function :) text/plain Bapt 2003-11-10 03:11 0000 5.69 KB Details
_portage New version text/plain Bapt 2003-11-11 11:46 0000 6.64 KB Details
_portage revised version of _portage text/plain Mamoru KOMACHI (RETIRED) 2003-12-24 08:53 0000 6.15 KB Details
_portage revision of the revised version ;) text/plain Bapt 2003-12-25 20:29 0000 6.14 KB Details
_portage.patch patch for the version include with zsh-4.1.1-r3 patch Bapt 2004-01-20 05:59 0000 4.03 KB Details | Diff
Create a New Attachment (proposed patch, testcase, etc.) View All

Bug 33130 depends on: Show dependency tree
Show dependency graph
Bug 33130 blocks:
Votes: 0    Show votes for this bug    Vote for this bug

Additional Comments: (this is where you put emerge --info)







View Bug Activity   |   Format For Printing   |   XML   |   Clone This Bug


Description:   Opened: 2003-11-10 03:10 0000
I've made a ZSH completion function for ZSH.
I think it will be a good idea to integrate it. It has completion for all emerge
option, completion for the available portages like this : name or cat/name;
completion for only installed portage with unmerge (cat/name) completion for
name with -s, ...

I think it's full featured

Reproducible: Always
Steps to Reproduce:
1. cp _portage /usr/share/zsh/version/function/Completion/Linux
2. compdef -a _portage emerge
3.

Actual Results:  
Really cool completion :)


copy that to _portage

---
#compdef emerge
_emerge () {
    local state
    if (( CURRENT == 2 ));then
        _arguments -s \
            '*:*:->actions' \
            "$common_args[@]" "$install_args[@]" && return 0
    elif (( CURRENT > 2 ));then
            case "$words[2]" in
            unmerge)
                _arguments -s \
                '*:installed pkg:_unmerge' "$common_args[@]" && return 0
            ;;
           
clean|depclean|-c|-C|help|-h|info|regen|sync|rsync|--searchdesc|-S|inject|-j|prune|-P);;
            search|-s)
	    	    _arguments -s \
		        '*:portage:_search_list' && return 0
	            ;;
            *)
                _arguments -s \
                '*:*:->install_portage' \
                "$common_args[@]" \
        		"$install_args[@]" && return 0
             ;;
             esac
    fi
    while [[ -n "$state" ]]; do
        lstate=$state
        state=''
        case "$lstate" in
        actions)
            _alternative \
            ':emerge actions:_actions' \
            '*:portage:_listportage' \
            '*:Ebuild files:_files -g \*.ebuild' 
        ;;
        install_portage)
            _alternative \
            '*:portage:_listportage' \
            '*:Ebuild files:_files -g \*.ebuild' 
        ;;
        esac
    done
}
#function to only show installed packages "cat/name"
_unmerge(){
	installed_portage=(/var/db/pkg/*/*)
	installed_dir=/var/db/pkg/
	installed_pkg=${(M)${${installed_portage//$installed_dir/$rem}%/}:#*-*}
	_tags -s installed_pkg && { compadd "$@" -k installed_pkg || compadd "$@"
${(kv)=installed_pkg} }
}
#Function to show only the name of all available portages
_search_list(){
	_tags -s search_portage && { compadd "$@" -k search_portage || compadd "$@"
${(kv)=search_portage} }
}

#Function to show all available portage like : "cat/name" and "name"
_listportage(){
    portages_list="$portages_list world system"
	_tags -s portages_list && { compadd "$@" -k portages_list || compadd "$@"
${(kv)=portages_list} }
}

common_args=(
{'(-p)--pretend','(--pretend)-p'}'[simply  display  what would be done]'
{'(-d)--debug','(--debug)-d'}'[Tells emerge to run the emerge command in debug
mode]'
)
	install_args=(
{'(--upgradeonly -U --update -u --quiet -q --onlydeps -o --oneshot --nospinner
--noreplace -n --nodeps -O --noconfmem -D --deep --changelog --buildpkg -B -b
--buildpkgonly --emptytree -e -f --fetchonly)-l','(--upgradeonly -U --update -u
--quiet -q --onlydeps -o --nospinner --noreplace -n --nodeps -O --noconfmem -D
--deep --emptytree -e -f --fetchonly -l --buildpkg -b -B --buildpkgonly
)--changelog'}'[This will show the ChangeLog]'
{'(-b --buildpkgonly -B --changelog -l)--buildpkg','(--changelog -l --buildpkg
--buildpkgonly -B)-b'}'[Tells emerge to build binary packages]' \
{'(-B -b --buildpkg --changelog -l)--buildpkgonly','(--changelog -l
--buildpkgonly --buildpkg -b)-B'}'[Tells emerge to only build binary packages]' \
{'(-D --changelog -l)--deep','(-l --changelog --deep)-D'}'[Consider the entire
dependency tree of packages]'
{'(-e -l --changelog)--emptytree','(--emptytree -l --changelog)-e'}'[Only
consider glibc as installed packages]'
{'(-f -l --changelog)--fetchonly','(-l --changelog --fetchonly)-f'}'[Just
perform fetches for all packages]'
'(-l --changelog)--noconfmem[Causes portage to disregard merge records]'
{'(--changelog -l -O)--nodeps','(--nodeps --changelog -l)-O'}'[Merges specified
 packages  without  merging  dependencies]'
{'(-l --changelog -n)--noreplace','(-l --changelog --noreplace)-n'}'[Skip
packages already installed]'
'(-l --changelog)--nospiner[Disables the spinner for the session]'
'(-l --changelog)--oneshot[Do not add package to the world profile]'
{'(--onlydeps --changelog -l)-o','(--changelog -o -l)--onlydeps'}'[Only  merge 
(or pretend to merge) the dependencies]'
{'(--quiet --changelog -l)-q','(-q --changelog -l)--quiet'}'[General outcome is
a reduced  or  condensed output]'
{'(--update --changelog -l)-u','(-u --changelog -l)--update'}'[Updates packages
to the most  recent  version  available]'
{'(--upgradeonly --changelog -l)-U','(-U --changelog -l)--upgradeonly'}'[Do not
update packages to a lower version]'
{'(--verbose)-v','(-v)--verbose'}'[Tell  emerge to run in verbose mode]'
)

_options() {
    _arguments -s \
    "$unmerge_args[@]" "$common_args[@]" "$install_args[@]"
}


_actions() {
    _values "emerge actions" \
    'sync[Initiates a portage tree update]' \
    'rsync[Initiates a portage tree update]' \
    'unmerge[Removes all matching packages]' \
    'search[Searches for matches]' \
    'regen[Causes  portage  to check and update the dependency cache]' \
    'prune[Removes  all but the latest versions of matching packages]' \
    'inject[Portage thinks that this package is installed]' \
    'info[This is a list of information to include in  bug  reports]' \
    'help[Displays help]' \
    'depclean[Clean all packages that have no reason for being installed]'\
    'clean[Cleans the system by removing packages]' \
    '-c[Cleans the system by removing packages]' \
    '-h[Displays help]' \
    '-i[Portage thinks that this package is installed]' \
    '-P[Removes  all but the latest versions of matching packages]' \
    '-s[Searches for matches]' \
    '-S[Matches the search string against the description field]' \
    '--searchdesc[Matches the search string against the description field]' \
    '-C[Removes all matching packages]' \
    'world[Represente all packages in the world profiles]' \
    'system[Represent all the system packages]' 
}

portages=(/usr/portage/*/*)
portagedir=/usr/portage/
rem=''
portages_list=${${(M)${${${portages//$portagedir/$rem}%/}:#*.eclass}:#*-*}:#*.*}
search_portage=${${(M)${${${${${portages//$portagedir/$rem}:#distfi*}:#licens*}%/}:#*.eclass}:#*-*}:t}

portages_list="$portages_list $search_portage"
_emerge "$@"
----

------- Comment #1 From Bapt 2003-11-10 03:11:51 0000 -------
Created an attachment (id=20512) [edit]
the completion function :)

------- Comment #2 From Seemant Kulleen (RETIRED) 2003-11-10 15:45:03 0000 -------
USata, can you also put a metadata.xml file there if you are the maintainer?

------- Comment #3 From Mamoru KOMACHI (RETIRED) 2003-11-10 22:43:21 0000 -------
Looks pretty nice :) However, PORTDIR needn't be /usr/portage and you
can set it by /etc/make.conf and environment variables (the same thing
applies to PORTDIR_OVERLAY). Can you rewrite portages part, please? Also,
-C is a synonym of unmerge, so 

case "$words[2]" in
    unmerge)

should be

case "$words[2]" in
    unmerge|-C)

Seemant: Added metadata.xml to zsh.

------- Comment #4 From Bapt 2003-11-11 09:21:30 0000 -------
I'll have a look for the PORTDIR and the PORTDIR_OVERLAY and unmerge|-C.
But it's the first time I contribute to gentoo, and I don't know what your
speaking about with metadata.xml ???

------- Comment #5 From Mamoru KOMACHI (RETIRED) 2003-11-11 09:30:38 0000 -------
Never mind, metadata.xml is a file to describe which packages belong
to whom/which group. I added metadata.xml so that it is clear I'm a
maintainer of zsh atm (if not present, seemant will assign bugs to
people in recent ChangeLog of each package) and all the bugs of zsh
will be assinged to me.

------- Comment #6 From Bapt 2003-11-11 11:46:32 0000 -------
Created an attachment (id=20602) [edit]
New version

Now PORTDIR and PORTDIR_OVERLAY are checked in the make.conf file and used.
corrected for unmerge, -C

------- Comment #7 From Mamoru KOMACHI (RETIRED) 2003-11-13 13:59:50 0000 -------
Thanks for quick response. I tried your completion function and it
looks wonderful except for speed. I rewrote the function to use cache
but it still "hangs" two or three seconds when I first run emerge
completion on my machine (and it takes more than 15 seconds to list
all the available package names).

Probably it is better to 1) only list category names, pkgnames,
ebuilds, world and system 2) if a category name is completed then add
a '/' and list pkgnames under that category afterwards. If I omit 
cat/pkg completion from your completion, the number of candidates 
shrink from about 12000 to 6000 and completion time goes down
drastically (0.5 sec to start completion, and 3 sec to list all
candidates). Will you rewrite your function accordingly?

------- Comment #8 From Bapt 2003-11-14 06:37:41 0000 -------
My english is perhaps poorer than I thought (I'm french) but your first
proposition is (for me) exactly what is done currently.
I'll try to rewrite my function according to your second proposition, but my
skills in ZSH programing are not really strong so it could take a long time ;)

------- Comment #9 From Mamoru KOMACHI (RETIRED) 2003-11-14 07:12:09 0000 -------
No worries ;-) I should state what I think is the problem clearly (I'm
japanese). As I read though your function and actually used it, it  completes
12000 candidates [ pkgnames(6000) + cat/pkgnames(6000) + world(1) + system(1) +
ebuild files(?) ] (the number of candidates are show in parentheses) while in
my suggestion it completes 6000 candidates [ category names(100) +
pkgnames(6000) + world(1) + system(1) + ebuild files(?) ].  It's okay for
taking some time. Zsh 4.0.8 and 4.1.2 will soon be released and if this
function is ready at the time I'll be very pleased to include it to Portage
along with the release, but feel free to do it at your pace. I'm sure users
will appreciate your help and effort at any time. If you finish it after the
release of new zsh, I'll include it as zsh-4.0.8-r1/zsh-4.1.2-r1 anyhow ;-) 

------- Comment #10 From Mamoru KOMACHI (RETIRED) 2003-12-17 02:22:51 0000 -------
Hi, how's it going? I'll work on this so that we could include it to Portage in
time the upcoming zsh release. 

------- Comment #11 From Bapt 2003-12-17 07:01:19 0000 -------
I've managed to separate cat and names and to get a completion like cat[tab]
automated append of a "/" but I can't currently manage to continue the
completion :(

As I said before, my skills are not really strong.

But you were right, the process is faster. now that zsh-4.0.8 is released I
can't have a working new version soon enough for this ebuild.

------- Comment #12 From Mamoru KOMACHI (RETIRED) 2003-12-24 08:53:01 0000 -------
Created an attachment (id=22624) [edit]
revised version of _portage

------- Comment #13 From Mamoru KOMACHI (RETIRED) 2003-12-24 08:57:03 0000 -------
I rewrote _portage based on yours to make it run a little faster.
Please have a look and test it, and if it is ok with you I'll include
it into Portage along with zsh 4.0.9 (released last week). Merry
Christmas! ;)

------- Comment #14 From Bapt 2003-12-25 12:25:46 0000 -------
The revised version seems to work great, and it is from far cleaner ;). should
be ok for zsh 4.0.9, I'll try to work on this one to improve it a few. Merry
Christmas ! 

------- Comment #15 From Bapt 2003-12-25 20:29:07 0000 -------
Created an attachment (id=22666) [edit]
revision of the revised version ;)

After trying a little bit more the revised function I've made some correction
for mistakes on completing the emerge options. For all the rest it's now very
good :)

------- Comment #16 From Mamoru KOMACHI (RETIRED) 2003-12-28 11:55:13 0000 -------
Thanks, I added tbz2file completion when -K (--usepkgonly) is
specified and committed it with zsh-4.0.9.ebuild and zsh-4.1.1-r3.ebuild.
Thanks for the great contribution ;)

------- Comment #17 From Mikael Magnusson 2004-01-16 10:36:12 0000 -------
emerge clean <tab> does nothing, i think it should complete installed packages
without version numbers and world/system

------- Comment #18 From Mamoru KOMACHI (RETIRED) 2004-01-18 10:07:11 0000 -------
Yeah, thanks for reporting. Included the modification to zsh-4.1.1-r4
and zsh-4.0.9-r2.

------- Comment #19 From Bapt 2004-01-20 05:59:54 0000 -------
Created an attachment (id=24127) [edit]
patch for the version include with zsh-4.1.1-r3

Added completion for opengl-update rc rc-update rc-status and ebuild
Everything work fine with me, try it ;)

PS: the patch is made against the version in zsh-4.1.1-r3 with the not working
clean option :)

------- Comment #20 From Mamoru KOMACHI (RETIRED) 2004-02-04 07:58:46 0000 -------
Hi, thanks again, baptux. Good job! (I often forget what arguments I
should give to rc-update.. hehe) I included them as zsh-4.1.1-r5 and
zsh-4.0.9-r3. Just I want to tell you, many people told me that they
enjoy tab complete you contributed ;)

First Last Prev Next    No search results available      Search page      Enter new bug