bash tab 补全无需变量扩展?
假设我在 bashrc 中定义了这些变量:
i='cgi-bin/internal';
e='cgi-bin/external';
f='cgi-bin/foo';
b='cgi-bin/bar';
ad='cgi-bin/admin';
#etc...
当我在命令行上使用变量时 vim $i/edit_
TAB 它将展开命令行上的变量和输入变成 vim /www/productX/subdomain_x/cgi-bin/internal/edit_
(无论我在哪个网站),然后我 TAB< /kbd>TAB 获取可能的补全。
没关系,功能不是问题。只是每次看到完整路径而不仅仅是变量值会很烦人。
有没有办法在不影响功能的情况下不在命令行上扩展 bash 变量?
这是 bash 完成吗?
期望的结果是 $i
不扩展为其值(视觉上)或 $i
扩展为相对路径而不是完整路径。
Let's say I have these variables defined in my bashrc
:
i='cgi-bin/internal';
e='cgi-bin/external';
f='cgi-bin/foo';
b='cgi-bin/bar';
ad='cgi-bin/admin';
#etc...
When I use the variable on the command line vim $i/edit_
TAB it will expand the variable and the input on the command line becomes vim /www/productX/subdomain_x/cgi-bin/internal/edit_
(respective to whatever site I'm on) and then I TABTAB to get the possible completions.
That's fine, the functionality isn't the problem. It's just that it can get annoying to see the full path every time rather than just the value of the variable.
Is there a way to not expand the bash variables on the command line without compromising functionality?
Is it the bash completion that's doing this?
The desired outcome would be $i
not expanding to it's value (visually) or $i
expanding to a relative path rather than the full path.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我不确定您在 bash 启动脚本中使用了哪些其他设置,但对我来说,以下 bash 命令可以解决问题:
I am not sure which other settings you use in your bash startup scripts, but for me the following bash command does the trick:
shopt -u direxpand
-u
:禁用(取消设置)shell 可选行为标志direxpand
:使用
shopt direxpand
检查当前状态(或使用shopt
检查所有选项)。使用
shopt -s direxpand
重新启用Soure:
https://www.gnu.org/software/ bash/manual/html_node/The-Shopt-Builtin.html
shopt -u direxpand
-u
: Disable (unset) shell optional behavior flagdirexpand
:Check current status with
shopt direxpand
(or all options withshopt
).Re-enable with
shopt -s direxpand
Soure:
https://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html
您可以尝试使用
zsh
而不是bash
。在 zsh 中,将 $i 扩展为相对路径
(另外 Oh My Zsh 非常适合自定义)
You might try using
zsh
instead ofbash
. In zsh,expands $i to a relative path
(Also Oh My Zsh is great for customizing zsh)
使用
<代码>
购物-u progcomp
为我工作,此后选项卡不再扩展变量。
一个shopt文档
https://www.gnu.org/software/ bash/manual/html_node/The-Shopt-Builtin.html
Using
shopt -u progcomp
worked for me, after this the tab did not expand variables anymore.
A shopt doc
https://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html