Skip to content

Instantly share code, notes, and snippets.

@ndevenish
Last active March 22, 2019 13:51
Show Gist options
  • Save ndevenish/c4acc1ec2c971bef6179667e03555c12 to your computer and use it in GitHub Desktop.
Save ndevenish/c4acc1ec2c971bef6179667e03555c12 to your computer and use it in GitHub Desktop.
# Work out if we're Redhat
if [ -f /etc/redhat-release ] ; then
DIST='RH'
OS_MAJOR=$(lsb_release -r | awk '{print $2;}' | cut -d. -f1 | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' )
OS_SHORT=$DIST$OS_MAJOR
PS1_OS="\[\e[35m\]RH${OS_MAJOR}\[\e[0m\] "
fi
# This adds 'PHI' to the PS1 if on a Xeon Phi box
if cat /proc/cpuinfo | grep 'name'| uniq | grep Phi > /dev/null; then
PS1_OS="${PS1_OS}\[\e[1m\]PHI\[\e[0m\] "
fi
# Setup git, from https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh
source ~/.git-prompt.sh
export GIT_PS1_SHOWDIRTYSTATE=1
export GIT_PS1_SHOWCOLORHINTS=1
# Then I use it in my prompt command, but PS1 would work just as well
# Form is
# <OS> <hostname> <short-dir> <git-info-if-needed> $
# Where the $ is colored red if the last command failed
export PROMPT_COMMAND='__git_ps1 "$PS1_OS\h \[\e[1;31m\]\W\[\e[0m\]" "\[$([ $? -eq 0 ] || printf "\e[1;31m")\]\\\$\[\e[0m\] "'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment