更新:您可以自定义自动完成的程序称为complete
。
您可以在这里找到一些很好的基本示例:More on Using the Bash Complete Command
使用功能和脚本名称按照上面的链接,在此可以追加/
符号链接到一个目录的脚本...这仅仅是一个粗略的样本,但它表明这是可以做到(我还没有与cd
内置试过......
助理功能_mycomplete_
具有可执行myfoo
complete -F _mycomplete_ myfoo
功能在~/.bashrc
function _mycomplete_()
{
local cmd="${1##*/}"
local word=${COMP_WORDS[COMP_CWORD]}
local line=${COMP_LINE}
local xpat='!*.foo'
COMPREPLY=($(compgen -f -X "$xpat" -- "${word}"))
if ((${#COMPREPLY[@]}==1)) ;then
[[ -h $COMPREPLY ]] && COMPREPLY="$COMPREPLY/"
fi
}
原来的答复去:
在命令行中,自动扩展的符号链接的主要指标是显示在最后下表中的行,即。一个名字扩大但没有最后的/
。
on pressing TAB on pressing TAB (again)
what happens? meaning what happens?
=================== ======================= ====================================
Nothing is appended 1=> Multiple sub-dirs exist => A list of possibilities is presented
2=> No sub-directory exists => Nothing is appended (again)
Expands to end in/ => A uniquely matching dir => ...as per first column (repeat)
Expands text only => Current name is a link => Expands to end in/
在你的例子中,如果你已经准备好命令行的全名,即。 cd link
那么指标不明显。你也不会知道它是通过可能性列表的符号链接。
为了能够cd
向链接的目标,你可以使用cd -P link
,或set -P; cd link
谷歌搜索 “的bash自动完成符号链接目录” 认定:http://unix.stackexchange.com/questions/14337/why-is- bash完成符号链接不同于目录http://superuser.com/questions/155167/tab-completion-with-directories-links http://superuser.com/questions/271626/ bash-autocomplete -symlink-to-directory-complete-to-whole-directory-including – huon 2012-04-12 08:56:50
第一个链接是关于find,而不是bash autocompletion。 第二个链接是关于自动完成符号链接。这不是我的情况,因为subdir是一个常规目录。另外我想我已经把mark-symlinked-directories设置为已经输入'cd li [tab]'autocompletes to'cd link /' 这些链接都没有告诉我如何完成到'cd ../ subdir /' – mbonnin 2012-04-12 09:42:24