mwf*_*ley 206 command-line bash auto-completion case-insensitive
Ubuntu 的终端使用区分大小写的自动完成功能,正如我认为 Linux 所期望的那样。
但我认为使用不区分大小写的名称通常会更方便,以节省您在开始名称时必须准确的情况,并且可能值得额外的误报。是否有可能改变这种行为?
Pan*_*her 238
为了使bash当前用户不区分大小写:
在终端中运行以下 shell 脚本:
# If ~/.inputrc doesn't exist yet: First include the original /etc/inputrc
# so it won't get overriden
if [ ! -a ~/.inputrc ]; then echo '$include /etc/inputrc' > ~/.inputrc; fi
# Add shell-option to ~/.inputrc to enable case-insensitive tab completion
echo 'set completion-ignore-case On' >> ~/.inputrc
Run Code Online (Sandbox Code Playgroud)
启动一个新的 shell(重新打开终端)。
要在系统范围内进行更改:
# add option to /etc/inputrc to enable case-insensitive tab completion for all users
echo 'set completion-ignore-case On' >> /etc/inputrc
# you may have to use this instead if you are not a superuser:
echo 'set completion-ignore-case On' | sudo tee -a /etc/inputrc
Run Code Online (Sandbox Code Playgroud)
有关详细信息,请参阅man bash。是的,这是一个很长的页面,但是 bash 是一个有点复杂的程序,如果您只想在该页面中搜索“不区分大小写”以转到相关部分。人们通常一次学习一个选项或一次学习一个 bash 脚本,掌握所有细微差别需要很长时间。您的兴趣可能会有所不同。
emt*_*in4 62
打开终端并输入以下命令:
echo set completion-ignore-case on | sudo tee -a /etc/inputrc
Run Code Online (Sandbox Code Playgroud)
输入密码。重启终端。
如果在某些情况下您想删除不区分大小写的内容,只需通过删除该set completion-ignore-case行来编辑 /etc/inputrc 文件。
就这样。
小智 23
我知道这个问题很老了,但除非我遗漏了一些东西,否则我认为如果您使用 bash,我有一个超级简单的解决方案。
echo "bind 'set completion-ignore-case on'" >> ~/.bashrc
Run Code Online (Sandbox Code Playgroud)
或者只是使用您最喜欢的文本编辑器添加该行。重新启动您的 bash 会话并享受。
您可以通过为 GNU 设置配置变量来完成此操作,该变量用于readline处理交互式 shell 中的输入。
所需的变量是completion-ignore-case,并且可以直接在您的 bash 会话中设置:
bind "set completion-ignore-case on"
Run Code Online (Sandbox Code Playgroud)
通过放入set completion-ignore-case on用户的~/.inputrc文件或系统/etc/inputrc,可以为所有未来的 bash 会话启用它,以便为所有用户启用它。这是 readline 的初始化文件。
(请注意,~/.inputrc可能不存在,你必须创建它,这将覆盖系统复制的/etc/inputrc。这有很多有用的配置键映射,如Ctrl-Left/ Right。
解决此问题的方法是将行$include /etc/inputrc放在 的顶部~/.inputrc,例如:
$include /etc/inputrc
set completion-ignore-case on
Run Code Online (Sandbox Code Playgroud)
然后重新启动 bash 或重新加载 inputrc,例如使用Ctrlx, Ctrlr。)
有关 readline 和 inputrc 的更多信息可以在man bash和 中找到man 3 readline。