Skip to content

Instantly share code, notes, and snippets.

@oxyc
Created January 10, 2012 17:51
Show Gist options
  • Save oxyc/1590225 to your computer and use it in GitHub Desktop.
Save oxyc/1590225 to your computer and use it in GitHub Desktop.
Bash prompt
# Logic stolen from https://github.com/gf3/dotfiles
parse_git_dirty() {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
parse_git_branch() {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1$(parse_git_dirty)/"
}
prompt_desc() {
OUTPUT=""
if [ -n "$SSH_CLIENT" ] ; then
OUTPUT="${OUTPUT}ssh/"
fi
if [[ -n $(git branch 2> /dev/null) ]] ; then
OUTPUT="${OUTPUT}$(parse_git_branch)/"
fi
[[ -n "$OUTPUT" ]] && echo " ${OUTPUT%?}"
}
CYAN="\033[0;36m"
WHITE="\033[0;37m"
RESET="\033[0m"
PS1="\[${WHITE}\]\w \[${CYAN}\]${USER}@${HOSTNAME}\[${WHITE}\]\$(prompt_desc) \[${RESET}\]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment