Skip to content

Instantly share code, notes, and snippets.

@mattions
Last active February 5, 2025 10:15
Show Gist options
  • Save mattions/360a5e6182597bb1015cb6dba5182537 to your computer and use it in GitHub Desktop.
Save mattions/360a5e6182597bb1015cb6dba5182537 to your computer and use it in GitHub Desktop.
gist to parse git output
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit, working tree clean" ]] && echo "*"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/(\1$(parse_git_dirty))/"
}
export PS1='\u@\h \[\033[1;33m\]\w\[\033[0m\]$(parse_git_branch)$ '
#grey
PS1='\[\033[0;32m\]\u\[\033[1;32m\]@\[\033[0;32m\]\h\[\033[00m\]:\[\033[01;34m\]\W\[\033[1;30m\]$(parse_git_branch)\[\033[00m\]\$ '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment