Tab 上的 Bash 变量扩展完成

发布于 2024-11-16 20:38:12 字数 274 浏览 3 评论 0原文

我正在运行 Ubuntu 11.04,当我尝试在 bash 中对以变量开头的路径使用制表符补全时,我看到一些奇怪的行为。如果我有 TOP=/scratch,并且我尝试制表符完成:

cd $TOP/foo

它会更改为:

cd \$TOP/foo

我希望它完成为: cd $TOP/foobar 或者 cd /scratch/foobar 但我会满足于不改变线路并要求我取消转义 $ 。

有谁知道我应该在 bash/readline 的哪里解决这个问题?

I'm running Ubuntu 11.04, and I'm seeing some odd behaviour when I try to use tab-completion in bash on a path that starts with a variable. If I've got TOP=/scratch, and I try to tab-complete:

cd $TOP/foo

it changes to:

cd \$TOP/foo

I'd prefer it to complete to:
cd $TOP/foobar
or
cd /scratch/foobar
but I'd settle for it just not changing the line and requiring me to un-escape the $.

Does anyone know where in bash/readline I should look to fix this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

明天过后 2024-11-23 20:38:12

找到错误报告,请注册(如果尚未注册)并将自己添加到“受影响的人员”列表中,我刚刚这样做了:

https://bugs.launchpad.net/ubuntu/+source/bash/+bug/778627

解决方法

尝试启用direxpandcdable_vars

shopt -s direxpand
# or
shopt -s cdable_vars

显然 EscTab 可能是一种解决方法

我还没有找到合适的解决方案,但有一个解决方法。可以通过按 Esc 键然后按 Tab 键来禁用环境变量的转义。

# cd $SO + [Esc] + [Tab]
# cd $SOME_DIR

<子>
确认这是一个错误!我刚刚确认同样的事情适用于,

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 10.10
Release:        10.10
Codename:       maverick

我在(最新的)natty 上得到了损坏的行为:

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 11.04
Release:    11.04
Codename:   natty

虽然我必须补充一点,我没有转义了斜杠,但是路径(虽然有效、现有、可访问和可读)没有得到扩展。

信息:https://help.ubuntu.com/community/ReportingBugs

Found the bug report, please register (if not already registered) and add yourself to the 'people affected' list, I just did:

https://bugs.launchpad.net/ubuntu/+source/bash/+bug/778627

Workarounds

Try enabling direxpand or cdable_vars:

shopt -s direxpand
# or
shopt -s cdable_vars

Apparently EscTab might be a workaround:

I haven't found a proper solution to this, but there's a workaround. The escaping of environment variables can be disabled by pressing Esc followed by tab.

# cd $SO + [Esc] + [Tab]
# cd $SOME_DIR


Confirm that as a bug! I just confirmed that the same thing works on

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 10.10
Release:        10.10
Codename:       maverick

I get broken behaviour on (up-to-date) natty:

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 11.04
Release:    11.04
Codename:   natty

Although I must add that I do not the slash escaped, but the path (while valid, existing, accessible and readable) is not getting expanded.

Info: https://help.ubuntu.com/community/ReportingBugs

鹿港巷口少年归 2024-11-23 20:38:12

其他答案中提到的错误报告 bugs.launchpad.net 通过发出命令给出了新的解决方法:

shopt -s direxpand

它对我有用。

The bug report refered to in other answers at bugs.launchpad.net gives a new workaround by issuing the command:

shopt -s direxpand

It works for me.

靑春怀旧 2024-11-23 20:38:12

我在 cygwin (NT-6.1 2.0.1 2015-04-30) bash (GNU 4.3.33) 中遇到类似的问题,特别是当我尝试制表符扩展包含空格的路径时。

我将 shopt -s direxpand 放入我的 ~/.bashrc 中。问题解决了。

I was having a similar problem in cygwin (NT-6.1 2.0.1 2015-04-30) bash (GNU 4.3.33), especially when I would try to tab-expand a path that contained spaces.

I put shopt -s direxpand in my ~/.bashrc. Problem solved.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文