2

I have bash-completion installed, and I get a lot of mileage out of tab-completing CDPATH entries when using cd. I'd like to get the same functionality from pushd. I started diving into the bash-completion source code, but I'm a little out of my depth.

1

Try adding this to your .bash_profile:

# Taken from /usr/share/bash-completion/bash_completion on my
# Ubuntu 16.04 system, substituting "pushd" for "cd":
if shopt -q cdable_vars; then
    complete -v -F _cd -o nospace pushd
else
    complete -F _cd -o nospace pushd
fi

Works for me. Note that it's indented, as it's "protected" by an if [ -n "$PS1" ], to ensure it doesn't run for a non-interactive session. (My .bashrc run .bash_profile to handle some ways that shells are started, such as via ESC-x shell in GNU Emacs, which reads only .bashrc.)

  • 1
    It looks like, since I originally posted, the bash-completion scripts have been updated and include this out of the box. – ivan Sep 11 '18 at 22:38

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.