Skip to content

Instantly share code, notes, and snippets.

@sallyom
Last active March 21, 2022 17:09
Show Gist options
  • Save sallyom/7562cc5e84192b9c6be7470f2e87f71c to your computer and use it in GitHub Desktop.
Save sallyom/7562cc5e84192b9c6be7470f2e87f71c to your computer and use it in GitHub Desktop.
fancy git terminal prompt to place in ~/.bashrc
# Helper function for fancy git prompt.
# Place this in ~/.bashrc
# Then, `source ~/.bashrc` will execute the prompt function w/out having to reboot
# (otherwise, any ~/.bashrc settings take effect with every reboot.
# Lines 7-38 go in ~/.bashrc
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
# Fancy prompt function
function proml {
local BLUE="\[\033[0;34m\]"
local RED="\[\033[0;31m\]"
local LIGHT_RED="\[\033[1;31m\]"
local GREEN="\[\033[0;32m\]"
local LIGHT_GREEN="\[\033[1;32m\]"
local WHITE="\[\033[1;37m\]"
local LIGHT_GRAY="\[\033[0;37m\]"
local BLACK="\[\033[0;30m\]"
local RESET="\[\e[0m\]"
case $TERM in
xterm*)
TITLEBAR='\[\033]0;\u@\h:\w\007\]'
;;
*)
TITLEBAR=""
;;
esac
PS1="\h$RED:$BLUE\W$RED\$(parse_git_branch)${RESET}$ "
PS2='> '
PS4='+ '
}
# Call the fancy prompt function
proml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment