To be able to enter dev my-[tab]
anywhere on my system and receive auto completion like
$ dev my-[tab]
my-project
my-awesome-project
I created a file in /etc/bash_completion.d/
with the following content:
_dev()
{
PROJECTS=$(ls /development)
local cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=( $(compgen -W "${PROJECTS}" -- $cur) )
}
complete -F _dev dev
This works just fine, but I would also like to be able to auto-complete subfolders:
[~] $ dev my-p[tab]
[~] $ dev my-project/[tab][tab]
src doc
[~] $ dev my-project/s[tab][enter]
[/development/my-project/src] $
So basically, I would like to have auto-completion for dev
the same way it is for cd
.
dev
is only an alias:
alias dev='gotodev'
gotodev ()
{
cd /development/$1
}
Just wrote an example: