1

I've been relying on this hack for jumping around in the file system for a couple of years before finding out today that I can do the same thing using native Bash by activating the option cdable_vars.

The only thing I miss is tab completion. If I put this in my .bashrc or .bash_profile:

shopt -s cdable_vars
export mydir="$HOME/my/nested/directory"

Tab completion isn't expanding mydir when I try to cd into it from the prompt. Is there a way to activate this behavior in Bash?

3

To activate this completion you need the bash-completion package.

If the package is installed (often by default) just add these lines in your .bashrc

if [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
fi

If not: https://bash-completion.alioth.debian.org/

  • Weird, I've always used completion everywhere without having this installed. Anyway now it does what I want, thanks a lot! – zool Nov 24 '15 at 13:15
  • The tab completion works with the cd command, though I use the path often with the mv command, which does not work. I wonder, if it could work as well. – xralf Jun 22 '17 at 22:04
  • @djangoliv Your link is broken – Max Coplan Feb 11 at 18:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.