【发布时间】:2014-02-25 13:07:34
【问题描述】:
compgen shell 内置有两个困难。
我尝试用简单的 bash _filedir-like(使用 ls)代码来展示它:
_myfiledir(){
path="$cur"
prefix=`echo /$path | grep -o "[0-9a-Z\-+_/]*/"`
sufix=`echo /$path | grep "/[0-9a-Z\-+_]*$" | grep -o "[0-9a-Z\-+_]*$"`
res=`ls -p $prefix`
COMPREPLY=($( compgen -o nospace -W "$res" -- $sufix ))
}
在这种情况下,cur=="usr/li" 然后是 prefix=="/usr/" 和 sufix=="li"
我有两个困难。有空间和更换。例如:
$ script usr/li[TAB]
我明白了:
$ script lib/ <- additional space here
我需要:
$ script usr/lib/ <- no space here
此代码仅作为示例。
【问题讨论】:
标签: bash autocomplete compgen