Skip to content

Instantly share code, notes, and snippets.

@amolbrid
Created November 22, 2010 20:52
Show Gist options
  • Save amolbrid/710658 to your computer and use it in GitHub Desktop.
Save amolbrid/710658 to your computer and use it in GitHub Desktop.
# ----------- Set prompt to show working git branch ------------------
# inspired by fowlduck's http://gist.github.com/4477
# unfortuneately if I echo ansi codes it messes with line wrapping on the
# command line,
# guessing because unlike ansi codes in a VAR it doesn't know the real size of
# the string when echo'd :(
# doesn't matter if the codes are set using tput or straight up raw ansi
function git_prompt {
BRANCH=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1/"`
if [ -n "${BRANCH}" ]; then
echo -en "(${BRANCH})"
fi
}
function myprompt {
local NUTTN="\[\033[0m\]"
local BLUE="\[\033[0;34m\]"
local GREEN="\[\033[0;32m\]"
local CYAN="\[\033[1;36m\]"
local RED="\[\033[0;31m\]"
local WHITE="\[\033[0;37m\]"
local BRED="\[\033[1;31m\]"
local BGREEN="\[\033[1;32m\]"
local BWHITE="\[\033[1;37m\]"
PS1="${NUTTN}${BGREEN}\w${NUTTN}${CYAN}\$(git_prompt)${BRED}\$${NUTTN} "
}
myprompt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment