Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash tab completion without variable expansion?

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.

like image 867
Andrew Sohn Avatar asked Feb 08 '11 19:02

Andrew Sohn


People also ask

Does bash have tab completion?

Bourne shell and csh do not, but ksh, bash, tcsh, and zsh all have tab completion to varying degrees. The basic principle in all of these shells is the same; you type the start of the word, hit the <TAB> key twice, and the list of possible commands or files is displayed.

How do bash completions work?

Bash completion is a bash function that allows you to auto complete commands or arguments by typing partially commands or arguments, then pressing the [Tab] key. This will help you when writing the bash command in terminal.

What is bash parameter expansion?

Bash uses the value formed by expanding the rest of parameter as the new parameter ; this is then expanded and that value is used in the rest of the expansion, rather than the expansion of the original parameter . This is known as indirect expansion .


1 Answers

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)

like image 96
k107 Avatar answered Sep 18 '22 13:09

k107