Skip to content

Instantly share code, notes, and snippets.

@irlevesque
Created July 23, 2015 01:00
Show Gist options
  • Save irlevesque/9362ad78dfe1e7c7a352 to your computer and use it in GitHub Desktop.
Save irlevesque/9362ad78dfe1e7c7a352 to your computer and use it in GitHub Desktop.
Git prompt
# If we're in a git repo, print the first 9 characters of the current committish.
function parse_git_commit() {
git rev-parse HEAD 2>/dev/null | cut -c1-10
}
# If we're in a git repo, print the current branch name. The sed call deletes
# any line not starting with '* ', then removes the '* '
function parse_git_branch () {
git rev-parse --abbrev-ref HEAD 2>/dev/null
}
# If we're in a git repo, print "@(<branchname>:<committish>)"
function current_git_info (){
branch=`parse_git_branch`
commit=`parse_git_commit`
# If branch is not empty
if [ ! -z "$branch" ]
then
echo "@($branch:$commit)";
fi
}
PS1='$(current_git_info) \[\e[0;32m\][\u@\h]\[\e[m\] \[\e[1m\][\t] \[\e[1;34m\][\w]\[\e[m\]\n \$ \[\e[m\]'
@irlevesque
Copy link
Author

screenshot 2015-07-22 21 02 04

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