help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] Command completion for an alias


From: Chet Ramey
Subject: Re: [Help-bash] Command completion for an alias
Date: Thu, 04 Jun 2015 12:05:30 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:31.0) Gecko/20100101 Thunderbird/31.7.0

On 5/30/15 8:15 AM, address@hidden wrote:
> Hi folks!
> 
> My .bashrc defines some aliases like alias gs='git status'. I'd like to
> enable command completion for aliases so that when the command line is (|
> is the cursor):
> 
> $ gs |
> 
> and I press Tab I'd like to see the completions as if I typed 'git status
> '. I found a bunch of resources demonstrating how to do this [1][2][3] but
> in my opinion they lack elegance. My question is: how to make completion
> work for aliases? If bash needs to modified where should I start looking in
> the source code?

This is something that's been on the list for a while, and I've thought
about some of the issues.

Frankly, I think the solution presented by Ole is pretty elegant, and
can be customized to do whatever you want.  If I were to use it, I would
modify it using pieces of Hesky Fisher's solution so you only have to
specify the alias name and can use sed (or your text-processing tool of
choice) to extract the alias definition given an alias name.

If you want to take a look at the bash source to see about adding this,
you'd have to add another if statement in
pcomplete.c:programmable_completions before the DEFAULTCMD case.  It would
look up the alias definition and adjust `cmd' accordingly, but would
also have to modify the readline line buffer, `start', `end', and make sure
the right things happened in command_line_to_word_list.  That's all easy
to do when you have single words as the alias value, but not so much when
the alias expands to multiple words.  Using the wrapper function does a
lot of that for you at the expense of restricting it to shell functions.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]