Skip to content

Git prompt. #10

@greg-a-atkinson

Description

@greg-a-atkinson

Hi,

I like your Git prompt. Here's a variation to use or lose.

Clean working tree:

user@host:~/dev/src/Project [master]
$

Dirty working tree:

user@host:~/dev/src/Project [master:?+±→x↓↑]
$

function identify_git_branch() {
branch=$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* (.*)/\1/')
if [[ $branch != "" ]]; then
status=$(git status 2>&1 | tee)
flags=""

# Symbols: ☺☻♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▀▐αßΓπΣσµΦΘΩδ∞φε∩≡±≥≤⌠⌡≈÷°∙√ⁿ²■ü

untracked=$(echo -n "${status}" 2> /dev/null | grep "Untracked files:" &> /dev/null; echo "$?")
if [[ ${untracked} == 0 ]]; then flags="${flags}?"; fi

newfile=$(echo -n "${status}" 2> /dev/null | grep "new file:" &> /dev/null; echo "$?")
if [[ ${newfile} == 0 ]]; then flags="${flags}+"; fi

modified=$(echo -n "${status}" 2> /dev/null | grep "modified:" &> /dev/null; echo "$?")
if [[ ${modified} == 0 ]]; then flags="${flags}±"; fi

renamed=$(echo -n "${status}" 2> /dev/null | grep "renamed:" &> /dev/null; echo $?)
if [[ ${renamed} == 0 ]]; then flags="${flags}→ "; fi

deleted=$(echo -n "${status}" 2> /dev/null | grep "deleted:" &> /dev/null; echo "$?")
if [[ ${deleted} == 0 ]]; then flags="${flags}x"; fi

behind=$(echo -n  "${status}" 2> /dev/null | grep "Your branch is behind " &> /dev/null; echo "$?")
if [[ ${behind} == 0 ]]; then flags="${flags}↓"; fi

ahead=$(echo -n "${status}" 2> /dev/null | grep "Your branch is ahead of " &> /dev/null; echo "$?")
if [[ ${ahead} == 0 ]]; then flags="${flags}↑"; fi

if [[ $flags != "" ]]; then
  echo "[$branch:$flags]"
else
  echo "[$branch]"
fi

unset status flags renamed ahead behind newfile untracked deleted modified

fi
unset branch
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions