我正在學習bash完成。我只能列出當前目錄的內容。這裏是我的代碼:如何在其他目錄中擴展bash完成?
_foo()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="push pull"
OUTPUT=" $(ls) "
case "${prev}" in
push)
COMPREPLY=($(compgen -W "--in --out" -- ${cur}))
return 0
;;
--in)
COMPREPLY=($(compgen -W "$OUTPUT" -- ${cur}))
return 0
;;
esac
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
return 0
}
complete -F _foo foo
它的輸出是:
$ foo push --in[TAB]
file1.txt file2.txt foo ;; content of pwd
但是,當我這樣做:
$ foo push --in ~[TAB]
它不工作。 所以我想知道如何在不同目錄下執行bash完成(不僅在pwd)?謝謝。
哦,他們其實不是在腳本。這些僅僅是因爲Vim編輯器。我從那裏拷貝了這個腳本,所以行號也被複制了。 –