Skip to content

Instantly share code, notes, and snippets.

@thanosa75
Created November 29, 2012 17:06
Show Gist options
  • Save thanosa75/4170427 to your computer and use it in GitHub Desktop.
Save thanosa75/4170427 to your computer and use it in GitHub Desktop.
Colored prompt with git support
# add this snippet in your .bashrc and enjoy a green foreground color,
# with HH:MM time info, plus directory and git data on a directory that
# has git information (git repo)
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# parse and create the prompt
function parse_git_branch {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
lastcommit=$(git log -1|head -1|awk '{print $2}'|colrm 8)
echo "("${ref#refs/heads/}-$lastcommit")"
}
# colors!!!
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
# set the prompt
PS1="$RED\$(date +%H:%M) \w$YELLOW \$(parse_git_branch)$GREEN\$ "
@thanosa75
Copy link
Author

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