function parse_git_branch { git rev-parse --is-inside-work-tree &>/dev/null || return local branch=$(git symbolic-ref --short HEAD 2>/dev/null || git describe --tags --exact-match 2>/dev/null) echo "(${branch})" } ## ✗ ✓ ↑ ↓ ↲ ↲ ↳ ↴ ↵ ↺ ➔ ➙ ➜ ➥ function parse_git_status { local symbol="✓" # clean state (up to date) if git rev-parse --is-inside-work-tree &>/dev/null; then local branch branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null) # Ahead / behind remote if [[ "$branch" != "HEAD" ]]; then local behind=$(git rev-list --count HEAD..origin/$branch 2>/dev/null || echo 0) local ahead=$(git rev-list --count origin/$branch..HEAD 2>/dev/null || echo 0) if [[ "$ahead" -gt 0 ]]; then symbol="↑" elif [[ "$behind" -gt 0 ]]; then symbol="↓" fi fi # Unstaged changes if ! git diff --quiet 2>/dev/null; then symbol="✗" fi if ! git diff --cached --quiet 2>/dev/null; then symbol="✗" fi # untracked files if git ls-files --others --exclude-standard -z | grep -q .; then symbol="?" fi fi echo "${symbol}" } function set_PS1 { WHITE="\[\033[01;015m\]" YELLOW="\[\033[01;33m\]" BLUE="\[\033[01;34m\]" RED="\[\033[01;31m\]" PINK="\[\033[01;35m\]" RESET="\[\033[0m\]" if git rev-parse --is-inside-work-tree &>/dev/null; then PS1="${YELLOW}\u@\h ${BLUE}[$(basename "$PWD")]${RED}$(parse_git_branch) ${RESET}$(parse_git_status) ${PINK}\$:${RESET} " else PS1="${WHITE}\u@\h \$: ${RESET}" #PS1="\[\033[01;015m\]\u@\h $: \[\033[0m\]" fi } set_PS1 PROMPT_COMMAND=set_PS1