Sorry I couldn't post it before, I was kept at work, and the bind function was more error prone than I thought.
Here is what I came up with:
Bind the following script:
with the following command:
source "$HOME/.bashrc.d/autocomplete.sh" bind -x '"\t" : autocomplete_wrapper'
Output:
>$ cd /u/lo/b<TAB> >$ cd /usr/local/bin >$ cd /u/l<TAB> /usr/local /usr/lib >$ cd /usr/l
A binding string can be added to your ~/.bashrc , doing something like this:
if [[ -s "$HOME/.bashrc.d/autocomplete.sh" ]]; then source "$HOME/.bashrc.d/autocomplete.sh" bind -x '"\t" : autocomplete_wrapper' fi
(taken from this answer )
In addition, I highly recommend not binding this command to your Tab key, as it will override the default autocomplete.
Note: In some cases this will not be true, since isntance if you try to autocomplete "/path/with spaces/something" , since the last argument to complete is determined by ${READLINE_LINE##* } . If this is a problem in your case, you should encode a function that returns the last argument of the string when considering quotes
Feel free to ask for further clarification, and I welcome any suggestion to improve this script.
source share