简体   繁体   中英

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.

它并不完美,但解决方法是使用ESC ctrl-e强制扩展变量然后点击标签(至少在emacs模式下......不确定vi模式)

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM