Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@relaxdiego
Forked from johngibb/install-git-completion.sh
Last active July 30, 2018 19:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save relaxdiego/5758328 to your computer and use it in GitHub Desktop.
Save relaxdiego/5758328 to your computer and use it in GitHub Desktop.
GIT_VERSION=`git --version | awk '{print $3}'`
URL="https://raw.github.com/git/git/v$GIT_VERSION/contrib/completion/git-completion.bash"
PROFILE="$HOME/.bash_profile"
echo "Downloading git-completion for git version: $GIT_VERSION..."
if ! curl "$URL" --silent --output "$HOME/.git-completion.bash"; then
echo "ERROR: Couldn't download completion script. Make sure you have a working internet connection." && exit 1
fi
SOURCE_LINE=$(cat <<EOF
source ~/.git-completion.bash
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
NORMAL="\[\033[m\]"
PS1="$GREEN\w$YELLOW\$(__git_ps1)$NORMAL $ "
EOF
)
if [[ -f "$PROFILE" ]] && grep -q "$SOURCE_LINE" "$PROFILE"; then
echo "Already added to bash profile."
else
echo "Adding to bash profile..."
echo "$SOURCE_LINE" >> "$PROFILE"
fi
echo "Reloading bash profile..."
source "$PROFILE"
echo
echo "Successfully installed."
echo "Git auto-completion should be all set!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment