符号链接循环中意外的bash自动完成行为 [英] Unexpected bash autocompletion behavior within a symbolic link loop
问题描述
我有以下的目录结构:
底座/
DIR /
子目录/
链接 - > ../dir
现在,如果我cd到目录/链接,然后键入:
CD ../subd[tab]
我得到:
CD ../subdir[space]
-
如果自动完成失败(因为它会推崇的路径和调查的基础/我会听不懂DIR /).
-
我也明白,如果它要自动填充
CD ../子目录/
的结局/(因为这会间preT..
为进入上一层
并搜索到DIR /).
但我不明白,实际的行为是介于两者之间。理想情况下,我想的bash表现得像2.(自动完成到CD ../subdir/)。我使用的Fedora 14,bash的版本4.1.7(1)。任何想法如何做到这一点?
挖源$ C $ C位后,看起来这是一个有点复杂。实际的问题是bash的允许工作目录中的符号链接(见PWD -L和pwd -P)之间的混合,如果它不是一个物理目录的ReadLine无法确定匹配的类型
S =(nontrivial_match&安培;&安培; rl_completion_mark_symlink_dirs == 0)
? LSTAT(文件名,和放大器; finfo)
:STAT(文件名,和放大器; finfo);
统计()将失败,因为../被理解为相对于该物理路径,而不是逻辑路径。的readline未能确定这是一个目录,因此,不追加最终'/'。
一个非常类似的问题被描述这里
所以我想我可以用现有的行为活现在...
I have the following directory structure:
base/
dir/
subdir/
link -> ../dir
Now if I cd to dir/link and type:
cd ../subd[tab]
I get:
cd ../subdir[space]
I would understand if autocomplete fails (because it would canonize the path and look into base/ and not dir/).
I would also understand if it autocompletes to
cd ../subdir/
with the ending / (because it would interpret..
asgo up one level
and search into dir/).
But I do not understand the actual behaviour that is somewhere between the two. Ideally I would like bash to behave like 2. (autocomplete to cd ../subdir/). I am using fedora 14, bash version 4.1.7(1). Any idea how to accomplish this ?
After digging the source code a bit, it looks like this is a bit complicated. The actual problem is a mix between bash allowing symlinks inside the working directory (see pwd -L and pwd -P) and readline not able to determine the type of a match if it is not in a physical directory
s = (nontrivial_match && rl_completion_mark_symlink_dirs == 0)
? LSTAT (filename, &finfo)
: stat (filename, &finfo);
stat() fails since ../ is understood as relative to the physical path and not the logical path. readline fails to determine this is a directory and therefore does not append the final '/'. A very similar problem is described here
So I guess I can live with the existing behaviour for now...
这篇关于符号链接循环中意外的bash自动完成行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!