diff --git a/zsh/.zsh/prompt.zsh b/zsh/.zsh/prompt.zsh index c3003f2..b62b32b 100644 --- a/zsh/.zsh/prompt.zsh +++ b/zsh/.zsh/prompt.zsh @@ -1,31 +1,30 @@ #setopt promptsubst autoload -U colors && colors # Enable colors in prompt -# Show Git branch/tag, or name-rev if on detached head -function git_branch { +function git_prompt { local FULL_BRANCH="$(git symbolic-ref -q HEAD 2>/dev/null || git name-rev --name-only --no-undefined --always HEAD 2>/dev/null)" - local SHORT_BRANCH="$(echo $FULL_BRANCH | sed 's/refs\/heads\///')" - echo "$SHORT_BRANCH" -} + PBRANCH="$(echo $FULL_BRANCH | sed 's/refs\/heads\///')" + if [ -n $PBRANCH ]; then + echo -n " ${PBRANCH}" + # Are there unstaged changes in the working directory + local CHANGED=$(git status --porcelain --ignore-submodule -unormal 2>/dev/null | wc -l) + if [ $CHANGED -gt 0 ]; then + PCHANGED="◊" + fi + # Are we behind the origin? + local NUM_BEHIND="$(git log --oneline ..@{u} 2>/dev/null | wc -l | tr -d ' ' )" + if [ "$NUM_BEHIND" -gt 0 ]; then + PBEHIND="↓" + fi + # Are we ahead of the origin? + local NUM_AHEAD="$(git log --oneline @{u}.. 2>/dev/null | wc -l | tr -d ' ')" + if [ "$NUM_AHEAD" -gt 0 ]; then + PAHEAD="↑" + fi -function git_is_ahead { - local NUM_AHEAD="$(git log --oneline @{u}.. 2>/dev/null | wc -l | tr -d ' ')" - if [ "$NUM_AHEAD" -gt 0 ]; then - echo "↑" - fi -} - -function git_is_behind { - local NUM_BEHIND="$(git log --oneline ..@{u} 2>/dev/null | wc -l | tr -d ' ' )" - if [ "$NUM_BEHIND" -gt 0 ]; then - echo "↓" - fi -} - -function git_unstaged { - local CHANGED=$(git status --porcelain --ignore-submodule -unormal 2>/dev/null | wc -l) - if [ $CHANGED -gt 0 ]; then - echo -e "◊\c" + if [[ -n $PCHANGED || -n $PAHEAD || -n $PBEHIND ]]; then + echo -n " ${PCHANGED}${PBEHIND}${PAHEAD} " + fi fi } @@ -62,5 +61,5 @@ function check_reboot { test -f /var/run/reboot-required && echo "R " } -PROMPT='${PR_BOLD_RED}$(check_reboot)${reset_color}%m ${PR_BOLD_YELLOW}$(truncated_pwd 3)$(git_branch)%{$reset_color%}$(git_unstaged)$(git_is_ahead)$(git_is_behind) %(?.%F{magenta}.%F{red})❯%f ' +PROMPT='${PR_BOLD_RED}$(check_reboot)${reset_color}%m ${PR_BOLD_YELLOW}$(truncated_pwd 3)$(git_prompt)%(?.%F{magenta}.%F{red})❯%f ' #PROMPT='$(check_reboot)%m $(truncated_pwd 3) $(git_branch) $(git_unstaged)$(git_is_ahead)$(git_is_behind)> '