I'm learning about bash completion. I'm able to list the content of only current directory. Here is my code:
_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
It's output is:
$ foo push --in[TAB]
file1.txt file2.txt foo ;; content of pwd
But when I do this:
$ foo push --in ~[TAB]
It's not working. So I want to know how to do bash completion in different directory (not only in pwd)? Thanks.