summaryrefslogtreecommitdiffstats
path: root/radar-base.sh
diff options
context:
space:
mode:
authorClaudio Bandera <claudio.bandera@kit.edu>2015-09-17 18:40:24 +0200
committerClaudio Bandera <claudio.bandera@kit.edu>2015-09-17 18:40:24 +0200
commit92c2e869763dcc25c840c2e6cfcd9863abf201dd (patch)
treee032548195fccf98708daafa8f3e93c0781ede4e /radar-base.sh
parent2dbf0c220fc971c9493392a70c71954001fee7fd (diff)
parent1f6a8f84946a0cb6936916f47b5a3870fa12a5a6 (diff)
downloadgit-sonar-92c2e869763dcc25c840c2e6cfcd9863abf201dd.tar.gz
git-sonar-92c2e869763dcc25c840c2e6cfcd9863abf201dd.zip
Merge remote-tracking branch 'upstream/master' into hotfix/unittests
Diffstat (limited to 'radar-base.sh')
-rwxr-xr-xradar-base.sh229
1 files changed, 122 insertions, 107 deletions
diff --git a/radar-base.sh b/radar-base.sh
index 8d18fe3..41f4512 100755
--- a/radar-base.sh
+++ b/radar-base.sh
@@ -1,6 +1,75 @@
+NO_REMOTE_STATUS='--no-remote-status'
+
dot_git=""
cwd=""
remote=""
+rcfile_path="$HOME"
+
+prepare_bash_colors() {
+ if [ -f "$rcfile_path/.gitradarrc.bash" ]; then
+ source "$rcfile_path/.gitradarrc.bash"
+ elif [ -f "$rcfile_path/.gitradarrc" ]; then
+ source "$rcfile_path/.gitradarrc"
+ fi
+
+ PRINT_F_OPTION=""
+
+ COLOR_REMOTE_AHEAD="\x01${GIT_RADAR_COLOR_REMOTE_AHEAD:-"\\033[1;32m"}\x02"
+ COLOR_REMOTE_BEHIND="\x01${GIT_RADAR_COLOR_REMOTE_BEHIND:-"\\033[1;31m"}\x02"
+ COLOR_REMOTE_DIVERGED="\x01${GIT_RADAR_COLOR_REMOTE_DIVERGED:-"\\033[1;33m"}\x02"
+ COLOR_REMOTE_NOT_UPSTREAM="\x01${GIT_RADAR_COLOR_REMOTE_NOT_UPSTREAM:-"\\033[1;31m"}\x02"
+
+ COLOR_LOCAL_AHEAD="\x01${GIT_RADAR_COLOR_LOCAL_AHEAD:-"\\033[1;32m"}\x02"
+ COLOR_LOCAL_BEHIND="\x01${GIT_RADAR_COLOR_LOCAL_BEHIND:-"\\033[1;31m"}\x02"
+ COLOR_LOCAL_DIVERGED="\x01${GIT_RADAR_COLOR_LOCAL_DIVERGED:-"\\033[1;33m"}\x02"
+
+ COLOR_CHANGES_STAGED="\x01${GIT_RADAR_COLOR_CHANGES_STAGED:-"\\033[1;32m"}\x02"
+ COLOR_CHANGES_UNSTAGED="\x01${GIT_RADAR_COLOR_CHANGES_UNSTAGED:-"\\033[1;31m"}\x02"
+ COLOR_CHANGES_CONFLICTED="\x01${GIT_RADAR_COLOR_CHANGES_CONFLICTED:-"\\033[1;33m"}\x02"
+ COLOR_CHANGES_UNTRACKED="\x01${GIT_RADAR_COLOR_CHANGES_UNTRACKED:-"\\033[1;37m"}\x02"
+
+ COLOR_BRANCH="\x01${GIT_RADAR_COLOR_BRANCH:-"\\033[0m"}\x02"
+ MASTER_SYMBOL="${GIT_RADAR_MASTER_SYMBOL:-"\\x01\\033[0m\\x02\\xF0\\x9D\\x98\\xAE\\x01\\033[0m\\x02"}"
+
+ RESET_COLOR_LOCAL="\x01${GIT_RADAR_COLOR_LOCAL_RESET:-"\\033[0m"}\x02"
+ RESET_COLOR_REMOTE="\x01${GIT_RADAR_COLOR_REMOTE_RESET:-"\\033[0m"}\x02"
+ RESET_COLOR_CHANGES="\x01${GIT_RADAR_COLOR_CHANGES_RESET:-"\\033[0m"}\x02"
+ RESET_COLOR_BRANCH="\x01${GIT_RADAR_COLOR_BRANCH_RESET:-"\\033[0m"}\x02"
+}
+
+prepare_zsh_colors() {
+ if [ -f "$rcfile_path/.gitradarrc.zsh" ]; then
+ source "$rcfile_path/.gitradarrc.zsh"
+ elif [ -f "$rcfile_path/.gitradarrc" ]; then
+ source "$rcfile_path/.gitradarrc"
+ fi
+
+ PRINT_F_OPTION="%s"
+
+ COLOR_REMOTE_AHEAD="%{${GIT_RADAR_COLOR_REMOTE_AHEAD:-$fg_bold[green]}%}"
+ COLOR_REMOTE_BEHIND="%{${GIT_RADAR_COLOR_REMOTE_BEHIND:-$fg_bold[red]}%}"
+ COLOR_REMOTE_DIVERGED="%{${GIT_RADAR_COLOR_REMOTE_DIVERGED:-$fg_bold[yellow]}%}"
+ COLOR_REMOTE_NOT_UPSTREAM="%{${GIT_RADAR_COLOR_REMOTE_NOT_UPSTREAM:-$fg_bold[red]}%}"
+
+ COLOR_LOCAL_AHEAD="%{${GIT_RADAR_COLOR_LOCAL_AHEAD:-$fg_bold[green]}%}"
+ COLOR_LOCAL_BEHIND="%{${GIT_RADAR_COLOR_LOCAL_BEHIND:-$fg_bold[red]}%}"
+ COLOR_LOCAL_DIVERGED="%{${GIT_RADAR_COLOR_LOCAL_DIVERGED:-$fg_bold[yellow]}%}"
+
+ COLOR_CHANGES_STAGED="%{${GIT_RADAR_COLOR_CHANGES_STAGED:-$fg_bold[green]}%}"
+ COLOR_CHANGES_UNSTAGED="%{${GIT_RADAR_COLOR_CHANGES_UNSTAGED:-$fg_bold[red]}%}"
+ COLOR_CHANGES_CONFLICTED="%{${GIT_RADAR_COLOR_CHANGES_CONFLICTED:-$fg_bold[yellow]}%}"
+ COLOR_CHANGES_UNTRACKED="%{${GIT_RADAR_COLOR_CHANGES_UNTRACKED:-$fg_bold[white]}%}"
+
+ local italic_m="$(printf '\xF0\x9D\x98\xAE')"
+
+ COLOR_BRANCH="%{${GIT_RADAR_COLOR_BRANCH:-$reset_color}%}"
+ MASTER_SYMBOL="${GIT_RADAR_MASTER_SYMBOL:-"%{$reset_color%}$italic_m%{$reset_color%}"}"
+
+ RESET_COLOR_LOCAL="%{${GIT_RADAR_COLOR_LOCAL_RESET:-$reset_color}%}"
+ RESET_COLOR_REMOTE="%{${GIT_RADAR_COLOR_REMOTE_RESET:-$reset_color}%}"
+ RESET_COLOR_CHANGES="%{${GIT_RADAR_COLOR_CHANGES_RESET:-$reset_color}%}"
+ RESET_COLOR_BRANCH="%{${GIT_RADAR_COLOR_BRANCH_RESET:-$reset_color}%}"
+}
in_current_dir() {
local wd="$(pwd)"
@@ -115,12 +184,6 @@ branch_ref() {
fi
}
-readable_branch_name() {
- if is_repo; then
- printf '%s' "$(branch_name || printf '%s' "detached@$(commit_short_sha)")"
- fi
-}
-
remote_branch_name() {
local localRef="\/$(branch_name)$"
if [[ -n "$localRef" ]]; then
@@ -298,23 +361,17 @@ untracked_status() {
printf '%s' "$untracked_string"
}
-bash_color_changes_status() {
+color_changes_status() {
local separator="${1:- }"
local porcelain="$(porcelain_status)"
local changes=""
if [[ -n "$porcelain" ]]; then
- local green_staged_prefix="\x01\033[1;32m\x02"
- local red_unstaged_prefix="\x01\033[1;31m\x02"
- local yellow_conflicted_prefix="\x01\033[1;33m\x02"
- local grey_untracked_prefix="\x01\033[1;37m\x02"
- local reset_suffix="\x01\033[0m\x02"
-
- local staged_changes="$(staged_status "$porcelain" "$green_staged_prefix" "$reset_suffix")"
- local unstaged_changes="$(unstaged_status "$porcelain" "$red_unstaged_prefix" "$reset_suffix")"
- local untracked_changes="$(untracked_status "$porcelain" "$grey_untracked_prefix" "$reset_suffix")"
- local conflicted_changes="$(conflicted_status "$porcelain" "$yellow_conflicted_prefix" "$reset_suffix")"
+ local staged_changes="$(staged_status "$porcelain" "$COLOR_CHANGES_STAGED" "$RESET_COLOR_CHANGES")"
+ local unstaged_changes="$(unstaged_status "$porcelain" "$COLOR_CHANGES_UNSTAGED" "$RESET_COLOR_CHANGES")"
+ local untracked_changes="$(untracked_status "$porcelain" "$COLOR_CHANGES_UNTRACKED" "$RESET_COLOR_CHANGES")"
+ local conflicted_changes="$(conflicted_status "$porcelain" "$COLOR_CHANGES_CONFLICTED" "$RESET_COLOR_CHANGES")"
if [[ -n "$staged_changes" ]]; then
staged_changes="$separator$staged_changes"
fi
@@ -333,53 +390,23 @@ bash_color_changes_status() {
changes="$staged_changes$conflicted_changes$unstaged_changes$untracked_changes"
fi
- printf "$changes"
+ printf $PRINT_F_OPTION "$changes"
}
-zsh_color_changes_status() {
- local separator="${1:- }"
-
- local porcelain="$(porcelain_status)"
- local changes=""
-
- if [[ -n "$porcelain" ]]; then
- local staged_prefix="%{$fg_bold[green]%}"
- local unstaged_prefix="%{$fg_bold[red]%}"
- local conflicted_prefix="%{$fg_bold[yellow]%}"
- local untracked_prefix="%{$fg_bold[white]%}"
- local suffix="%{$reset_color%}"
-
- local staged_changes="$(staged_status "$porcelain" "$staged_prefix" "$suffix")"
- local unstaged_changes="$(unstaged_status "$porcelain" "$unstaged_prefix" "$suffix")"
- local untracked_changes="$(untracked_status "$porcelain" "$untracked_prefix" "$suffix")"
- local conflicted_changes="$(conflicted_status "$porcelain" "$conflicted_prefix" "$suffix")"
- if [[ -n "$staged_changes" ]]; then
- staged_changes="$separator$staged_changes"
- fi
-
- if [[ -n "$unstaged_changes" ]]; then
- unstaged_changes="$separator$unstaged_changes"
- fi
-
- if [[ -n "$conflicted_changes" ]]; then
- conflicted_changes="$separator$conflicted_changes"
- fi
-
- if [[ -n "$untracked_changes" ]]; then
- untracked_changes="$separator$untracked_changes"
- fi
+bash_color_changes_status() {
+ color_changes_status
+}
- changes="$staged_changes$conflicted_changes$unstaged_changes$untracked_changes"
- fi
- printf %s "$changes"
+zsh_color_changes_status() {
+ color_changes_status
}
-bash_color_local_commits() {
+color_local_commits() {
local separator="${1:- }"
- local green_ahead_arrow="\x01\033[1;32m\x02↑\x01\033[0m\x02"
- local red_behind_arrow="\x01\033[1;31m\x02↓\x01\033[0m\x02"
- local yellow_diverged_arrow="\x01\033[1;33m\x02⇵\x01\033[0m\x02"
+ local green_ahead_arrow="${COLOR_LOCAL_AHEAD}↑$RESET_COLOR_LOCAL"
+ local red_behind_arrow="${COLOR_LOCAL_BEHIND}↓$RESET_COLOR_LOCAL"
+ local yellow_diverged_arrow="${COLOR_LOCAL_DIVERGED}⇵$RESET_COLOR_LOCAL"
local local_commits=""
if remote_branch="$(remote_branch_name)"; then
@@ -394,78 +421,66 @@ bash_color_local_commits() {
local_commits="$separator$local_ahead$green_ahead_arrow"
fi
fi
- printf "$local_commits"
+ printf $PRINT_F_OPTION "$local_commits"
}
-zsh_color_local_commits() {
- local separator="${1:- }"
-
- local ahead_arrow="%{$fg_bold[green]%}↑%{$reset_color%}"
- local behind_arrow="%{$fg_bold[red]%}↓%{$reset_color%}"
- local diverged_arrow="%{$fg_bold[yellow]%}⇵%{$reset_color%}"
-
- local local_commits=""
- if remote_branch="$(remote_branch_name)"; then
- local_ahead="$(commits_ahead_of_remote "$remote_branch")"
- local_behind="$(commits_behind_of_remote "$remote_branch")"
+bash_color_local_commits() {
+ color_local_commits
+}
- if [[ "$local_behind" -gt "0" && "$local_ahead" -gt "0" ]]; then
- local_commits="$separator$local_behind$diverged_arrow$local_ahead"
- elif [[ "$local_behind" -gt "0" ]]; then
- local_commits="$separator$local_behind$behind_arrow"
- elif [[ "$local_ahead" -gt "0" ]]; then
- local_commits="$separator$local_ahead$ahead_arrow"
- fi
- fi
- printf %s "$local_commits"
+zsh_color_local_commits() {
+ color_local_commits
}
-bash_color_remote_commits() {
- local remote_master="\xF0\x9D\x98\xAE" # an italic m to represent master
- local green_ahead_arrow="\x01\033[1;32m\x02←\x01\033[0m\x02"
- local red_behind_arrow="\x01\033[1;31m\x02→\x01\033[0m\x02"
- local yellow_diverged_arrow="\x01\033[1;33m\x02⇄\x01\033[0m\x02"
- local not_upstream="\x01\033[1;31m\x02⚡\x01\033[0m\x02"
+color_remote_commits() {
+ local green_ahead_arrow="${COLOR_REMOTE_AHEAD}←$RESET_COLOR_REMOTE"
+ local red_behind_arrow="${COLOR_REMOTE_BEHIND}→$RESET_COLOR_REMOTE"
+ local yellow_diverged_arrow="${COLOR_REMOTE_DIVERGED}⇄$RESET_COLOR_REMOTE"
+ local not_upstream="${COLOR_REMOTE_NOT_UPSTREAM}⚡$RESET_COLOR_REMOTE"
if remote_branch="$(remote_branch_name)"; then
remote_ahead="$(remote_ahead_of_master "$remote_branch")"
remote_behind="$(remote_behind_of_master "$remote_branch")"
if [[ "$remote_behind" -gt "0" && "$remote_ahead" -gt "0" ]]; then
- remote="$remote_master $remote_behind $yellow_diverged_arrow $remote_ahead "
+ remote="$MASTER_SYMBOL $remote_behind $yellow_diverged_arrow $remote_ahead "
elif [[ "$remote_ahead" -gt "0" ]]; then
- remote="$remote_master $green_ahead_arrow $remote_ahead "
+ remote="$MASTER_SYMBOL $green_ahead_arrow $remote_ahead "
elif [[ "$remote_behind" -gt "0" ]]; then
- remote="$remote_master $remote_behind $red_behind_arrow "
+ remote="$MASTER_SYMBOL $remote_behind $red_behind_arrow "
fi
else
remote="upstream $not_upstream "
fi
- printf "$remote"
+ printf $PRINT_F_OPTION "$remote"
}
-zsh_color_remote_commits() {
- local remote_master="$(printf '\xF0\x9D\x98\xAE')" # an italic m to represent master
- local green_ahead_arrow="%{$fg_bold[green]%}←%{$reset_color%}"
- local red_behind_arrow="%{$fg_bold[red]%}→%{$reset_color%}"
- local yellow_diverged_arrow="%{$fg_bold[yellow]%}⇄%{$reset_color%}"
- local not_upstream="%{$fg_bold[red]%}⚡%{$reset_color%}"
+bash_color_remote_commits() {
+ color_remote_commits
+}
- if remote_branch="$(remote_branch_name)"; then
- remote_ahead="$(remote_ahead_of_master "$remote_branch")"
- remote_behind="$(remote_behind_of_master "$remote_branch")"
+zsh_color_remote_commits() {
+ color_remote_commits
+}
- if [[ "$remote_behind" -gt "0" && "$remote_ahead" -gt "0" ]]; then
- remote="$remote_master $remote_behind $yellow_diverged_arrow $remote_ahead "
- elif [[ "$remote_ahead" -gt "0" ]]; then
- remote="$remote_master $green_ahead_arrow $remote_ahead "
- elif [[ "$remote_behind" -gt "0" ]]; then
- remote="$remote_master $remote_behind $red_behind_arrow "
- fi
- else
- remote="upstream $not_upstream "
+readable_branch_name() {
+ if is_repo; then
+ printf $PRINT_F_OPTION "$COLOR_BRANCH$(branch_name || printf '%s' "detached@$(commit_short_sha)")$RESET_COLOR_BRANCH"
fi
+}
- printf %s "$remote"
+zsh_readable_branch_name() {
+ readable_branch_name
+}
+
+bash_readable_branch_name() {
+ readable_branch_name
+}
+
+show_remote_status() {
+ if [[ $@ == *$NO_REMOTE_STATUS* ]]; then
+ return 1 # don't show the git remote status
+ fi
+ return 0
}