Skip to content

Instantly share code, notes, and snippets.

@aruprakshit
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aruprakshit/87b1114e9342e926e95a to your computer and use it in GitHub Desktop.
Save aruprakshit/87b1114e9342e926e95a to your computer and use it in GitHub Desktop.
Git and Bash shell customizations

Get the git-promt.sh script here. Put it somewhere like ~/.git-prompt.sh. If you want to be all CLI about it, you could just run:

curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh -o ~/.git-prompt.sh

Now modify your your bash profile (it’s at ~/.bash-profile, in case you’re new to this stuff). Before the part of the file that declares what your prompt will look like (PS1=[...]), load in the script you just downloaded, like so:

# Load in the git branch prompt script.
source ~/.git-prompt.sh

Now add \$(__git_ps1) to your prompt declaration. You can put it wherever you like, but I think it’s best suited for the very end, right before the final dollar sign (\$) If you want to get all _fancy, you can make it a pretty color. My declaration looks like this:

PS1="\[$GREEN\]\t\[$RED\]-\[$BLUE\]\u\[$YELLOW\]\[$YELLOW\]\w\[\033[m\]\[$MAGENTA\]\$(__git_ps1)\[$WHITE\]\$ "

(See here for color definitions.)

This declaration results in a prompt looks like this when I’m in the directory ~/src/food52 and on the branch develop:

@aruprakshit
Copy link
Author

Copied from this blog.. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment