bash tab completion without variable expansion?

3k views Asked by At

Let's say I have these variables defined in my bashrc:

i='cgi-bin/internal';  
e='cgi-bin/external';  
f='cgi-bin/foo';  
b='cgi-bin/bar';  
ad='cgi-bin/admin';  
#etc...

When I use the variable on the command line vim $i/edit_TAB it will expand the variable and the input on the command line becomes vim /www/productX/subdomain_x/cgi-bin/internal/edit_ (respective to whatever site I'm on) and then I TABTAB to get the possible completions.

That's fine, the functionality isn't the problem. It's just that it can get annoying to see the full path every time rather than just the value of the variable.

Is there a way to not expand the bash variables on the command line without compromising functionality?
Is it the bash completion that's doing this?

The desired outcome would be $i not expanding to it's value (visually) or $i expanding to a relative path rather than the full path.

4

There are 4 answers

2
k107 On

You might try using zsh instead of bash. In zsh,

vim $i[tab]

expands $i to a relative path

(Also Oh My Zsh is great for customizing zsh)

0
Bernhard Bodenstorfer On

I am not sure which other settings you use in your bash startup scripts, but for me the following bash command does the trick:

complete -r -v
0
IAmHello On

shopt -u direxpand

  • -u: Disable (unset) shell optional behavior flag
  • direxpand:

If set, Bash replaces directory names with the results of word expansion when performing filename completion. This changes the contents of the readline editing buffer. If not set, Bash attempts to preserve what the user typed.

Check current status with shopt direxpand (or all options with shopt).

Re-enable with shopt -s direxpand

Soure: https://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html

1
aldo On

Using shopt -u progcomp worked for me, after this the tab did not expand variables anymore. A shopt doc https://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html