Prompt in bashrc
# ====== | |
# PROMPT | |
# ====== | |
# Set the prompt | |
# - Specify colors using \e[31;40m where 31 is the color and 40 is the background or | |
# - Select 1 for bold. | |
# - Wrap color specifiers in \[ and \] to ensure they don't affect word wrapping | |
# - Colours 30=black, 31=red, 32=green, 33=yellow, 34=blue, 35=purple, 36=teal, 37=white | |
function parse_git_stash { | |
# Build a string of "^" characters (one per stash on the current branch) | |
out="" | |
for i in $(git stash list 2> /dev/null | grep -o "$1" 2> /dev/null) | |
do | |
out="$out*" | |
done | |
echo "$out" | |
} | |
function parse_git_branch { | |
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/' | |
} | |
function git_branch { | |
branch=$(parse_git_branch) | |
if [[ $branch != "" ]]; then | |
echo -e "($branch)" | |
fi | |
} | |
function git_stashes { | |
branch=$(parse_git_branch) | |
if [[ $branch != "" ]]; then | |
stashes=$(parse_git_stash $branch) | |
if [[ $stashes != "" ]]; then | |
echo -e "$stashes " | |
else | |
echo " " | |
fi | |
fi | |
} | |
function background_jobs { | |
[[ $(jobs | wc -l) -gt 0 ]] && echo " <background>" | |
} | |
if [ `id -u` = 0 ]; then | |
# Root prompt | |
PS1="\[\e[31m\]\W \$ \[\e[m\]" | |
else | |
# Don't show host locally | |
if [ `uname` = "Darwin" ]; then | |
# User prompt | |
PS1="\[\e[32m\]\$(git_branch)\[\e[31m\]\$(git_stashes)\[\e[34m\]\W\[\e[31m\]\$(background_jobs)\[\e[m\] > \[\e[m\]" | |
else | |
PS1="\[\e[34m\]\h:\W \$ \[\e[m\]" | |
fi | |
fi | |
export PS1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment