Complete variables with cd command in bash
Hello,
lately I’ve been searching for a way to complete variables containing directories with the “cd” command in bash. This is very helpful if you have something like “cd $mydir/”. This is not actually working in debian bash-completion.
Then I’ve realized that other commands such as “ls” actually expand variables. I looked for some “complete” combo used for “ls” but not for “cd” in /etc/bash_completion and I came out with the following:
complete -F _longopt -o default cd
Luckily, this is exactly the command needed to enable variable expansion with the “cd” command. Put that in your .bashrc after loading bash_completion and you’re done.