开发者

Bash tab completion changed behavior

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.


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)


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜