bug-bash
[Top][All Lists]
Advanced

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

Re: cd completion using aliased cd command


From: Chet Ramey
Subject: Re: cd completion using aliased cd command
Date: Wed, 17 Jul 2013 11:06:57 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130509 Thunderbird/17.0.6

On 7/17/13 10:53 AM, Mark W. Johnson wrote:
> Linda,
> 
> Don't get hung up on:
> 
>       function _cd { command cd "$@"; }
>       alias cd=_cd
> 
> In my real _cd function it saves off the directories visited, but I didn't 
> want to complicate the issue, so I replaced my useful _cd function to 
> something useless but simpler to demonstrate the problem.
> 
> I did just update my version of bash, but unfortunately I'm not sure what 
> version I was previously running.
> 
> I have one piece of information that I don't understand.  If I unalias cd, I 
> still have the problem.  If however, I never set the alias there's no 
> problem.  If I set the alias but then unset -f _cd, I get:
> 
>       cd bash: completion: function `_cd' not found
> 
> So it's as if once the alias is set, tab completion always follows the alias 
> even after I unset it.

Alias expansion is performed when a function is defined.  Let's say you
have the above alias defined before you define your completions.  If you
define a shell function to produce the completions for `cd', and that shell
function uses `cd' to do its work, the cd -> _cd alias expansion will
have been performed before the shell function is called.

Enabling -x will allow you to see exactly what happens when you attempt
tab completion.

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



reply via email to

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