简体   繁体   English

Bash选项卡完成更改了行为

[英]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. 它非常有用:只需设置$ opt(例如,/ home / $ USER / projects / opt - 并从您的开发用户转到qa,生活,$ opt是$ opt。

As of the release of bash4.2, this behavior has changed. 截至发布bash4.2时,此行为已发生变化。 Now tab completion leads to an escaped $ sign. 现在标签完成导致转义$符号。

$opt/foo => \\$opt/foo <= not at all what I meant! $ opt / foo => \\ $ opt / foo <=根本不是我的意思!

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. zsh解决方案对我有用。 It was trivial converting my .bashrc => .zshrc, and I have some complex shell functions/aliases. 这是简单的转换我的.bashrc => .zshrc,我有一些复杂的shell函数/别名。

I agree, how in the world did the bash maintainer's break this very basic tab completion functionality. 我同意,bash维护者在世界上如何打破这个非常基本的标签完成功能。

Another solution, which I've not tried is using bash from another distribution. 另一个我没试过的解决方案是使用另一个发行版的bash。 I've only seen this in the Mint 13 release. 我只在Mint 13发行版中看到过这个。 Ubuntu/Fedora bash works fine. Ubuntu / Fedora bash运行正常。

Building on frankc's answer: Try putting the following into ~/.inputrc : 基于frankc的回答:尝试将以下内容放入~/.inputrc

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

then start a new shell. 然后开始一个新的shell。 What this does: 这是做什么的:

  • Changes the TAB key to insert two characters: ESC-Ctrl-e ESC-Ctrl-t. 更改TAB键以插入两个字符:ESC-Ctrl-e ESC-Ctrl-t。
  • Maps ESC-Ctrl-t to the complete function, which is what's usually invoked when you press TAB. 将ESC-Ctrl-t映射到complete功能,这是您按TAB时通常调用的功能。 (You could use any other key combination instead of ESC-Ctrl-t, but that one is normally unused.) (您可以使用任何其他组合键而不是ESC-Ctrl-t,但通常不使用它。)

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. 由于ESC-Ctrl-e已经映射到shell-expand-line函数,现在当你按TAB时,bash首先展开你的变量( $opt ),然后像往常一样自动完成。

The workarounds suggested here and elsewhere either failed altogether for me, or were too cumbersome to type. 这里和其他地方建议的变通方法对我来说完全失败,或者输入太麻烦。

Eventually, a friend recommended using zshell (zsh). 最终,一位朋友建议使用zshell(zsh)。 It works! 有用! I did no customizations, leaving my .zshrc blank. 我没有进行自定义,将.zshrc留空。

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. 它与我以前的工作方式略有不同:旧的bash风格和vi风格的混合。 Pressing tab displays a list of multiple options are possible, then tabbing again will start selecting from that list and alternating, like vi. 按Tab键显示可能的多个选项列表,然后再次选项卡将开始从该列表中选择并交替,如vi。

I am pretty happy. 我很开心

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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