Shell tab-completion and other helpful command-line tricks
derek at pointerstop.ca
Sat Jan 24 17:37:18 UTC 2009
Paul Rumelhart wrote:
> Derek Broughton wrote:
>> Nils Kassube wrote:
>> bash completion is fairly arcane to me, but aiui it's up to the
>> packager to add some relevant file with the completions. Everybody
>> have apt-get - so you can try "apt-get -<tab>". Unfortunately, apt-get's
>> completions are part of the default system, so the "apt" package doesn't
>> have a special file in it.
> I didn't know there were tab completion files involved. That's good to
> I've also found it works in some other programs that take input from the
> command-line, such as psql (an interface into Postgresql). I assume
> that's built in to the psql code, and doesn't have anything to do with
> the bash shell.
Nope, it's built into readline - which is part of bash (if I'm not
completely confused!). In any case, it's possible to get completions from
most such programs (and yes, I use it in psql all the time).
> There is a command called "compgen" that you can call that tells you
> what will be matched for whichever program. For example, if you want to
> find out what tab completion will find for users on your system that
> start with the letter "r", type: "compgen -A user -- r" and it should
> give you the same list that "user r<tab>" does. This could be helpful
> inside scripts for various user inputs. There is also a command called
> "complete" that you can use to assign tab completion to your program,
> but I haven't tried that one. I'll have to play around with some scripts.
Neat - I didn't know about those.
More information about the kubuntu-users