Well, it's official ... Bash completion has spoiled me :-) Finding no completion routines to work with 'equery', I decided that this was a good opportunity to learn how Bash completion works and scratch an itch at the same time.
Created attachment 34492 [details] Bash completion for 'equery' Any suggestions for improvements?
Did you know that theres a gentoo-completion project on SourceForge now? I've added the author and maintainer of it to CC and hope you could contact him directly to get your great work integrated into it. As he said before, he would hand out access to people if they want to help him working with it. If you don't want that i'm sure he'll add your add-on to the project to have one single place for gentoo-completion. Looks good to me. Maybe the package completion could be merged into one function which gets used by all gentoo completion functions which need a category/package completion.
http://sourceforge.net/projects/gentoo-bashcomp/
Zach, any plans on adding this to gentoo-bashcomp?
I'll add it in the next day or so. I only took a cursory glance at it, but it looks good to me. (I will let you know if I do make any changes and why.) In regards to a "universal" category/package name completion function, I'm all for it. I'll take a look at the provided function and see how it fits in with the needs of the other completion commands. Thanks for the addition and feedback.
I've committed the changes to CVS and released 1.0_beta2 of gentoo-bashcomp. I haven't done a lot of testing, but it seems to work as intended. I made some relatively minor changes to the posted script. I've detailed my rationalle for the changes below for those who are interested (exerpted from an e-mail I sent to Peter Jensen): "I changed the _pkgname function to also accept the current word as a parameter. My rational is derived from Christian's suggestion that the category/package name completion code be merged into one function. I can't say that this change is absolutely necessary (I still have to dive deeper in, and it's been a while since I looked at the code), but I thought it safer not to modify $cur, so as not to potentially confuse the calling function. One thing I've found to be a pain to deal with is the $OLDPWD variable. I believe I was looking through the bash_completion code one day and noticed that when there was a change of directory, it was done within a command substitution construct. For example, this # Are we completing a category? elif [[ ${prev} == "-c" || ${prev} == "--category" ]] then local oldpwd oldpwd=$OLDPWD cd /usr/portage/metadata/cache/ COMPREPLY=($(compgen -W "$(compgen -G '*')" -- $cur)) cd $OLDPWD OLDPWD=$oldpwd fi becomes this # Are we completing a category? elif [[ ${prev} == "-c" || ${prev} == "--category" ]]; then COMPREPLY=($(cd /usr/portage/metadata/cache; compgen -W "$(compgen -G '*')" -- $cur)) fi which makes it much more readable. Because the 'cd' command executes in a subshell, the current environment is unaffected and, not surprisingly, the user's $OLDPWD variable is left unchanged. There may be more repetition in having to do the actual directory change, but it does get rid of the $OLDPWD headache, which makes the code easier to follow and more concise. Other than that, I just made a few cosmetic and formatting changes for consistency and combined the 'uses' and 'which' case in _equery, as the code was the same in both." I'm going to deal with making the _pkgname function more generic at another time, as I think it will take a bit of thought to do properly. I also added several new options to the emerge command and removed the rsync action (replace by --sync, if I'm not mistaken) as its use has been deprecated. I think all the options are now present, but feel free anyone to let me know if I've missed any.
Christian, I think it would make sense to install the gentoo completion script into /usr/share/bash-completion/ and then make a symlink to it in /etc/bash_completion.d so as to be consistent with the rest of the optional packages. Granted, if users modify the script it would get overwritten during an upgrade as the installation directory isn't config protected. Any thoughts? Also, would you like me to file a new bug report regarding the latest file release?
I'm starting to think that a bash-completion-config might be in order...
> Also, would you like me to file a new bug report regarding the latest file release? Don't worry about it; I'll release 20040711-r1 first thing in the morning. > I'm starting to think that a bash-completion-config might be in order... oohhh, ciaran, do I smell another project? ;)
plz release/bump direct to the 2004-10-17-version :) http://freshmeat.net/projects/bashcompletion/?branch_id=20101&release_id=175980
Thank you Peter for the original completion script. Thank you Zach for including it and releasing the new version of gentoo-bashcomp. Thank you Daniel for pointing out the new release. bash-completion-20041017 will hit cvs in a minute. Cheers