Skip to content

Instantly share code, notes, and snippets.

@tschaub
Last active May 7, 2016 13:57
Show Gist options
  • Save tschaub/684a9086bab10ae3fdeb to your computer and use it in GitHub Desktop.
Save tschaub/684a9086bab10ae3fdeb to your computer and use it in GitHub Desktop.
#!/bin/bash
set -o errexit
# This script gives you git bash completion and a minimal
# prompt displaying the branch name.
PROFILE=""
if [ -f "$HOME/.bashrc" ]; then
PROFILE="$HOME/.bashrc"
elif [ -f "$HOME/.bash_profile" ]; then
PROFILE="$HOME/.bash_profile"
fi
if [ ! -f "$PROFILE" ]; then
echo >&2 "Unable to find ~/.bashrc or ~/.bash_profile"
exit 1
fi
COMPLETION_DIR=$HOME/opt/git/contrib/completion
if ! grep --quiet "git-completion.bash" $PROFILE; then
# Download the contrib scripts
mkdir -p $COMPLETION_DIR
pushd $COMPLETION_DIR
curl --silent --show-error --remote-name https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash
curl --silent --show-error --remote-name https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh
popd
echo >> $PROFILE
echo "# Set git autocompletion and PS1 integration" >> $PROFILE
echo ". $COMPLETION_DIR/git-completion.bash" >> $PROFILE
echo ". $COMPLETION_DIR/git-prompt.sh" >> $PROFILE
echo 'export PS1='"'"'\h:\W$(__git_ps1)\$ '"'" >> $PROFILE
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment