符号链接循环中出现意外的bash自动完成行为
我有以下目录结构:
base/ dir/ subdir/ link -> ../dir 现在,如果我cd到dir / link并输入: cd ../subd[tab] 我明白了: cd ../subdir[space] >我会理解自动完成是否失败(因为它会对路径进行封装并查看base /而不是dir /). 但我不明白两者之间的实际行为.理想情况下,我希望bash表现得像2.(autocomplete to cd ../subdir/).我正在使用fedora 14,bash版本4.1.7(1).知道怎么做到这一点? 解决方法
更新:您可以使用其自定义自动完成的程序称为完成.
你可以在这里找到一些很好的基本例子: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链接然后指标不明显.此外,您不会通过可能性列表知道它是一个符号链接. 为了能够cd到链接的目标,你可以使用cd -P link,或set -P; cd链接 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |