Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 55687 - Bash completion for the 'equery' command.
Summary: Bash completion for the 'equery' command.
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All All
: High enhancement (vote)
Assignee: Gentoo Shell Tools project
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-06-30 08:53 UTC by Peter Jensen
Modified: 2004-10-19 06:01 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
Bash completion for 'equery' (gentoo-equery,6.21 KB, text/plain)
2004-06-30 08:54 UTC, Peter Jensen
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Jensen 2004-06-30 08:53:40 UTC
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.
Comment 1 Peter Jensen 2004-06-30 08:54:51 UTC
Created attachment 34492 [details]
Bash completion for 'equery'

Any suggestions for improvements?
Comment 2 Christian Birchinger (RETIRED) gentoo-dev 2004-06-30 12:50:41 UTC
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.
Comment 3 Daniel Webert 2004-10-11 13:09:29 UTC
http://sourceforge.net/projects/gentoo-bashcomp/
Comment 4 Aaron Walker (RETIRED) gentoo-dev 2004-10-12 03:36:12 UTC
Zach, any plans on adding this to gentoo-bashcomp?
Comment 5 Zach Forrest 2004-10-12 13:43:08 UTC
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.
Comment 6 Zach Forrest 2004-10-18 11:06:29 UTC
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.
Comment 7 Zach Forrest 2004-10-18 11:15:58 UTC
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?
Comment 8 Ciaran McCreesh 2004-10-18 11:42:02 UTC
I'm starting to think that a bash-completion-config might be in order...
Comment 9 Aaron Walker (RETIRED) gentoo-dev 2004-10-18 16:37:55 UTC
> 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?  ;)
Comment 10 Daniel Webert 2004-10-18 18:20:03 UTC
plz release/bump direct to the 2004-10-17-version :)

http://freshmeat.net/projects/bashcompletion/?branch_id=20101&release_id=175980
Comment 11 Aaron Walker (RETIRED) gentoo-dev 2004-10-19 06:01:24 UTC
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