比方说,我有一个目录中有几个文件就像这样:
$ ls file1 file2 file3
而我想在bash中做一些tab完成:
$ cat file<tab> file1 file2 file3
我记得看到有人正在完成制表符,并且shell将下一个部分粗体显示,所以在这种情况下,它会加粗文件名的2和3 ,所以它看起来像这样:file 1 file 2 file 3
这将告诉你你应该input什么。
我认为这是zsh一个function,但有什么办法让它在bash ?
我不知道直接移植的function,但有一种方法可以在bash进行破解。 可编程完成允许你指定你想看到什么,当你按照调用程序的选项卡键时,允许(作为一个stream行的例子) ssh [tab]显示从~/.ssh/known_hosts自动完成选项。
这里有一些有用的资源:
介绍,来源和RPMs
用户贡献“完成”
更多的例子
还有更多的例子
当然,要复制上面指定的function,您必须使用完成的可编程方面来弄清楚并编写自己的函数。 Ubuntu 自带一套用户贡献补全 ,这是一个很好的起点。
在基于Red Hat的发行版中,有一个包完成。 这个软件包会填充/etc/bash_completion.d/目录,并具有多个程序的特定完成行为。 我在Fedora,Red Hat和CentOS下使用它。
yum install bash-completion
由于类似的function,我使用tcsh 。
这是我的/etc/csh.cshrc文件:
if ($?tcsh && $?prompt) then bindkey "\e[1~" beginning-of-line # Home bindkey "\e[7~" beginning-of-line # Home rxvt bindkey "\e[2~" overwrite-mode # Ins bindkey "\e[3~" delete-char # Delete bindkey "\e[4~" end-of-line # End bindkey "\e[8~" end-of-line # End rxvt bindkey -k up history-search-backward bindkey -k down history-search-forward set filec set prompt="[%B%m%b:%~] %n%# " set complete = enhance # important line set autolist # important line too alias ls 'ls -hA --color' alias ll 'ls -l' endif