模糊搜索目录名的最佳/适当算法是什么?我想要实现一个bash完成,它使用模糊搜索完成目录/文件名,但该算法似乎依赖于要匹配的字符串集。
发布于 2013-12-09 15:08:44
嗯..。这是一个有趣的提议。我会这样做:
首先,解析文件路径以获得最后一个斜杠之后的文本。
IFS='/' read -a filepath <<< '$string'
dirname=${filepath[${#filepath[@] - 1]}
接下来,使用find
获取当前路径中的所有直接子目录,并将它们添加到bash完成选项中。您可以使用=~
运算符代替in this answer描述的模糊搜索。
for i in 'find . -type d -maxdepth 1'; do
if [[ i =~ $dirname ]]; then
//add to bash completion option, unsure how to do this part
fi
done
但是,请注意,=~
是一个bash运算符.
https://stackoverflow.com/questions/20472994
复制相似问题