I have the following bash script that I source in my root directory:
ROOT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
eval "$(register-python-argcomplete ${ROOT_DIR}/bin/execute.py)"
The execute.py file has Python autocompletion enabled and it works perfectly when I use the full path to my script in the bash shell:
/absolute/path/to/root/bin/execute.py <Tab> # This works perfectly
Now I want to create an alias, say my_command, so that I don't have to provide the full path. I want to use just:
my_command <Tab>
I've tried creating a simple bash alias:
alias my_command="${ROOT_DIR}/bin/execute.py"
or a function:
my_command() {
${ROOT_DIR}/bin/execute.py "$@"
}
but neither of them works. Do you know how to achieve this goal without writing a separate bash completion script?
EDIT
I think I found something that works. Notice that calling
complete | grep _python_argcomplete
in the bash shell gets completion functions for given Python scripts. In this output, I've found mine
complete -o bashdefault -o default -o nospace -F _python_argcomplete /absolute/path/to/root/bin/execute.py
thus I've edited my bash script this way
ROOT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
_my_command_autocomplete() {
_python_argcomplete ${ROOT_DIR}/bin/execute.py
}
my_command() {
${ROOT_DIR}/bin/execute.py "$@"
}
eval "$(register-python-argcomplete ${ROOT_DIR}/bin/execute.py)"
complete -F _my_command_autocomplete my_command
and it worked