You can use the complete
command to run a custom function when you press tab. Add these lines to .bashrc:
# Solution written by izabera on freenode. tyvm!
#.bashrc
myfunction () {
local path oldpath ng=$(shopt -p nullglob)
shopt -s nullglob
printf -v path %q "${COMP_WORDS[COMP_CWORD]}"
oldpath=$path
path=${path//\//*/} path=${path#\*}
eval "COMPREPLY=($path*)"
if (( ${#COMPREPLY[@]} == 0 )); then COMPREPLY=("$oldpath"); fi
eval "$ng"
}
complete -D -F myfunction -o bashdefault -o default -o filenames
edit:
the -D flag was introduced in bash 4.1, the current bash version used by git-bash is 3.1.1.
The flag sets the completion function as the default, for any command that does not already have a completion function defined.
On 3.1.1, the best you can do is configure specific commands:
#.bashrc
myfunction () { ... }
complete -F myfunction -o bashdefault -o default -o filenames cd ls cp mv node npm