2
我想啓用bash tab-complete來查找目錄,但不是在當前目錄中。如何從不同的路徑啓用bash選項卡完成?
因此,舉例來說,如果我這樣做:
$ ls $P
dirs/ are/ here/
$ cd /not/the/P/path
$ ls
other/ stuff/
$ myProg <tab>
dirs/ are/ here
這改變了通常的行爲,在那裏我通常會看到在當前目錄下的文件。
盡職調查:最好我能想出是:
_myProg()
{
local cur
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
if [ "${P}x" = "x" ]; then
return 1
fi
case "$cur" in
*)
pth=${P}/$(echo $cur | egrep -o "^.*/[^/]*$")
COMPREPLY=($(compgen -W "$(cd $pth && ls -1d "$cur"* 2>/dev/null -- "$cur")"))
;;
esac
return 0
}
complete -o nospace -F _myProg myProg
最初顯示的目錄,但犯規讓我鑽到我多麼希望的目錄(如ls
作品)。
「P」和「G」如何設置?看起來他們在調用之間攜帶了不想要的狀態。 – chepner