符号链接循环中意外的bash自动完成行为 [英] Unexpected bash autocompletion behavior within a symbolic link loop

查看:171
本文介绍了符号链接循环中意外的bash自动完成行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的目录结构:

 底座/
  DIR /
    子目录/
    链接 - > ../dir

现在,如果我cd到目录/链接,然后键入:

  CD ../subd[tab]

我得到:

  CD ../subdir[space]


  1. 如果自动完成失败(因为它会推崇的路径和调查的基础/我会听不懂DIR /).


  2. 我也明白,如果它要自动填充 CD ../子目录/ 的结局/(因为这会间preT .. 进入上一层并搜索到DIR /).


但我不明白,实际的行为是介于两者之间。理想情况下,我想的bash表现得像2.(自动完成到CD ../subdir/)。我使用的Fedora 14,bash的版本4.1.7(1)。任何想法如何做到这一点?


解决方案

挖源$ C ​​$ C位后,看起来这是一个有点复杂。实际的问题是bash的允许工作目录中的符号链接(见PWD -L和pwd -P)之间的混合,如果它不是一个物理目录的ReadLine无法确定匹配的类型

的readline / complete.c:1694

  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] 

  1. I would understand if autocomplete fails (because it would canonize the path and look into base/ and not dir/).

  2. I would also understand if it autocompletes to cd ../subdir/ with the ending / (because it would interpret .. as go 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

In readline/complete.c:1694

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆