Getting bash completion on OS X and Linux

Published on October 11, 2015 in How-tos
Read time: 1 min
Tags:

  1. Install bash-completion

on OS X:

sudo port install bash-completion

on Linux:

sudo apt-get install bash-completion
  1. Paste this in your .bashrc / .bash_profile

on OS X:

# MacPorts Bash shell command completion
if [ -f /opt/local/etc/bash_completion ]; then
    . /opt/local/etc/bash_completion
fi

or for MacPorts since version 2.1.2 on Mountain Lion:

# MacPorts Bash shell command completion
if [ -f /opt/local/etc/profile.d/bash_completion.sh ]; then
  . /opt/local/etc/profile.d/bash_completion.sh
fi

or for MacPorts with newer versions of git:

if [ -f /opt/local/share/git-core/git-prompt.sh ]; then
    . /opt/local/share/git-core/git-prompt.sh
fi

Note: Bash 4.1 or higher is required by bash_completion.sh. If completion doesn’t work try echo $BASH_VERSION to see if that’s the issue. If so, enter MacPorts bash by typing bash and try git completion again.

On Linux:

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
    . /etc/bash_completion
fi

Thanks for reading.


Sources:

  • https://superuser.com/questions/31744/how-to-get-git-completion-bash-to-work-on-mac-os-x

  • https://askubuntu.com/questions/33440/tab-completion-doesnt-work-for-commands



Comments

Got some words you want to share? Tell me!