Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

How do I prevent Zshell (and Bash I assume) from expanding environment variables in paths be completed as shown in the following example:

$PREFIX/alt/li

should expand to

$PREFIX/alt/lib

and not to say

/opt/alt/lib
share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

This is the default behavior under zsh. The complete-word and expand-or-complete zle widgets don't expand parameters whose value is a directory name, as long as there's a / after it (i.e. $foo/<TAB>).

There are many ways to customize this behavior. For example, maybe you've set up Tab to run expand-or-complete-prefix. There are also styles such as expand and keep-prefix that affect this behavior as well.

share|improve this answer
add comment

Assuming you have a literal directory called $PREFIX, just prepend a \ before the $, for \$PREFIX, then your tab completion will work. If you don't have a literal directory called $PREFIX, then autocomplete will not work, because it needs to expand $PREFIX in order to determine what values are valid for the autocompletion.

share|improve this answer
    
This is not what I want. $PREFIX is not a literal directory but an environment variable PREFIX whose value is /opt which I want to use in path completion. However, I don't want it to be expanded to /opt by the shell during completion. –  Nordlöw Sep 26 '12 at 13:31
    
The I amend my answer to "No. There is no way to suppress expansion of any type of variable during auto-completion." –  Tim Kennedy Sep 26 '12 at 13:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.