我有這樣的bash補全文件如何僅在bash自動完成中顯示第一級子目錄?
#/etc/bash_completion.d/mycommand
_mycommand()
{
local cur
COMPREPLY=()
_init_completion || return
#Variable to hold the current word
cur="${COMP_WORDS[COMP_CWORD]}"
#array variable COMPREPLY
dirs=('Rootdir/
Secondrootdir/
Rootdir/Subdir/
Secondrootdir/Anothersubdir/
Secondrootdir/Thirdsubdir/
Secondrootdir/Anothersubdir/Subsubdir/'
)
COMPREPLY=($(compgen -W "$dirs" "$cur"))
}
#Assign the auto-completion function _mycommand for our command mycommand.
complete -F _mycommand mycommand
當我有多種選擇,按下tab鍵兩次我看到以下內容:
$ mycommand Secondrootdir/
Secondrootdir/
Secondrootdir/Anothersubdir/
Secondrootdir/Anothersubdir/Subsubdir/
Secondrootdir/Thirdsubdir/
但我想看看進入電流僅爲一級深度子目錄Secondrootdir
這樣的:
$ mycommand Secondrootdir/
Anothersubdir/ Thirdsubdir/
CD命令執行業務以及
$ cd Music/
kattymusic/ Playlists/ Relax/
但我不明白爲什麼CD自動完成的作品。
有人可以幫我嗎?
號他們是遠程服務器。我只能使用API接收他們的列表。 – Oleg
謝謝。很好的例子,但我想要相反的事情。 – Oleg
我會在這方面付出更大的努力,並希望我能成功。 – Oleg