From 8eb15ef73385f7b8634c8e06f247a447e5ab7c7b Mon Sep 17 00:00:00 2001 From: Paul Joey Clark Date: Thu, 30 Jun 2016 17:07:26 +0800 Subject: [PATCH] Slightly cleaner structure --- prompt.sh | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/prompt.sh b/prompt.sh index e65cdaa..3b03b06 100644 --- a/prompt.sh +++ b/prompt.sh @@ -7,6 +7,7 @@ find_git_branch() { local branch local upstream local is_branch + local special_state if branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null); then if [[ "$branch" == "HEAD" ]]; then # Check for tag. From jordi-adell's branch. @@ -25,24 +26,26 @@ find_git_branch() { upstream=$(git rev-parse '@{upstream}' 2> /dev/null) is_branch=true fi - if [[ -n "$is_branch" && -n "$upstream" ]]; then - git_branch=" [$branch]" # Branch has an upstream - elif [[ -n "$is_branch" ]]; then - git_branch=" ($branch)" # Branch has no upstream - else - git_branch=" <$branch>" # Detached - fi local git_dir="$(git rev-parse --show-toplevel)/.git" if [[ -d "$git_dir/rebase-merge" ]] || [[ -d "$git_dir/rebase-apply" ]]; then - git_branch=" {$branch\\rebase}" + special_state=rebase elif [[ -f "$git_dir/MERGE_HEAD" ]]; then - git_branch=" {$branch\\merge}" + special_state=merge elif [[ -f "$git_dir/CHERRY_PICK_HEAD" ]]; then - git_branch=" {$branch\\pick}" + special_state=pick elif [[ -f "$git_dir/REVERT_HEAD" ]]; then - git_branch=" {$branch\\revert}" + special_state=revert elif [[ -f "$git_dir/BISECT_LOG" ]]; then - git_branch=" {$branch\\bisect}" + special_state=bisect + fi + if [[ -n "$special_state" ]]; then + git_branch=" {$branch\\$special_state}" + elif [[ -n "$is_branch" && -n "$upstream" ]]; then + git_branch=" [$branch]" # Branch has an upstream + elif [[ -n "$is_branch" ]]; then + git_branch=" ($branch)" # Branch has no upstream + else + git_branch=" <$branch>" # Detached fi else git_branch=""