4

For a long time, I have been used to being able to type something like:

$opt/foo/m

and so on to navigate my project within different environments. It is really useful: just set up $opt (say, /home/$USER/projects/opt - and go from your dev user, to qa, to live, and $opt is $opt.

As of the release of bash4.2, this behavior has changed. Now tab completion leads to an escaped $ sign.

$opt/foo => \$opt/foo <= not at all what I meant!

While the maintainers are discussing how this should work, I would like to find a new set of habits I could use to get back to my comfort zone. What would be a good trick? Something that my fingers could learn, to have some root configured and go from there without worrying about where I am.

KateYoak
  • 1,591
  • 3
  • 18
  • 34
  • It does. But usually what you want is: $opt/foobar/modules/Foo/Bar.pm and typing that without ever doing tab completion is painful. :-) – KateYoak Sep 23 '11 at 19:33
  • Please register as 'affects me' at the existing bug report [Bash variable expansion on tab complete](http://stackoverflow.com/questions/6418493/bash-variable-expansion-on-tab-complete/6418681#6418681) – sehe Sep 23 '11 at 20:33

4 Answers4

1

It's not perfect, but a workaround is to use ESC ctrl-e to force expansion of the variable before hitting tab (at least in emacs mode...not sure about vi mode)

frankc
  • 11,290
  • 4
  • 32
  • 49
0

zsh solution is all that worked for me. It was trivial converting my .bashrc => .zshrc, and I have some complex shell functions/aliases.

I agree, how in the world did the bash maintainer's break this very basic tab completion functionality.

Another solution, which I've not tried is using bash from another distribution. I've only seen this in the Mint 13 release. Ubuntu/Fedora bash works fine.

numberer6
  • 131
  • 1
  • 1
0

Building on frankc's answer: Try putting the following into ~/.inputrc:

"TAB": "\M-\C-e\M-\C-t"
"\M-\C-t": complete

then start a new shell. What this does:

  • Changes the TAB key to insert two characters: ESC-Ctrl-e ESC-Ctrl-t.
  • Maps ESC-Ctrl-t to the complete function, which is what's usually invoked when you press TAB. (You could use any other key combination instead of ESC-Ctrl-t, but that one is normally unused.)

Since ESC-Ctrl-e is already mapped to the shell-expand-line function, now when you press TAB, bash first expands your variable ($opt), then autocompletes as usual.

Andrew Schulman
  • 3,395
  • 1
  • 21
  • 23
  • This is a nice approach! Only it did not seem to have any effect. I tried to put it into ~/.inputrc and directly into /etc/inputrc. No good. How could I troubleshoot it? – KateYoak Nov 02 '11 at 16:41
  • After you change .inputrc, be sure that you either start a new shell, or press C-x C-r to reload .inputrc. – Andrew Schulman Nov 02 '11 at 16:56
0

The workarounds suggested here and elsewhere either failed altogether for me, or were too cumbersome to type.

Eventually, a friend recommended using zshell (zsh). It works! I did no customizations, leaving my .zshrc blank.

Now I got my tab completion back in order. It works a little differently than I am used to: a mix of old bash-style and vi-style. Pressing tab displays a list of multiple options are possible, then tabbing again will start selecting from that list and alternating, like vi.

I am pretty happy.

KateYoak
  • 1,591
  • 3
  • 18
  • 34