summaryrefslogtreecommitdiffstats
path: root/radar-base.sh
diff options
context:
space:
mode:
authorClaudio Bandera <claudio.bandera@kit.edu>2015-10-16 16:33:50 +0200
committerClaudio Bandera <claudio.bandera@kit.edu>2015-10-16 16:33:50 +0200
commit127e3e5b6d9f95062c6e05e083fbda1860eb647f (patch)
treedaebcb43bcc937582d7b0c0ccff8e8eb025c7803 /radar-base.sh
parent740cb5bb91d832b4bdb608280ff7df6812d21e92 (diff)
parent4cd0f2683c43cff423f85de4c1c74831fb3f1bbb (diff)
downloadgit-sonar-127e3e5b6d9f95062c6e05e083fbda1860eb647f.tar.gz
git-sonar-127e3e5b6d9f95062c6e05e083fbda1860eb647f.zip
Merge branch 'michaeldfallen-cbandera_stash_indicator' into feature/stash_indicator
Diffstat (limited to 'radar-base.sh')
-rwxr-xr-xradar-base.sh97
1 files changed, 85 insertions, 12 deletions
diff --git a/radar-base.sh b/radar-base.sh
index b8ab1f2..c355f3c 100755
--- a/radar-base.sh
+++ b/radar-base.sh
@@ -5,6 +5,14 @@ cwd=""
remote=""
rcfile_path="$HOME"
+timethis() {
+ cmd="$@"
+ start=$(gdate +%s.%N)
+ eval $cmd
+ dur=$(echo "$(gdate +%s.%N) - $start" | bc)
+ echo "$1 - $dur" >> $HOME/duration.dat
+}
+
prepare_bash_colors() {
if [ -f "$rcfile_path/.gitradarrc.bash" ]; then
source "$rcfile_path/.gitradarrc.bash"
@@ -33,6 +41,8 @@ prepare_bash_colors() {
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"}"
+ PROMPT_FORMAT="${GIT_RADAR_FORMAT:-" \\x01\\033[1;30m\\x02git:(\\x01\\033[0m\\x02%{remote: }%{branch}%{ :local}\\x01\\033[1;30m\\x02)\\x01\\033[0m\\x02%{ :stash}%{ :changes}"}"
+
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"
@@ -71,6 +81,8 @@ prepare_zsh_colors() {
COLOR_BRANCH="%{${GIT_RADAR_COLOR_BRANCH:-$reset_color}%}"
MASTER_SYMBOL="${GIT_RADAR_MASTER_SYMBOL:-"%{$reset_color%}$italic_m%{$reset_color%}"}"
+ PROMPT_FORMAT="${GIT_RADAR_FORMAT:-" %{$fg_bold[grey]%}git:(%{$reset_color%}%{remote: }%{branch}%{ :local}%{$fg_bold[grey]%})%{$reset_color%}%{ :stash}%{ :changes}"}"
+
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}%}"
@@ -397,7 +409,7 @@ color_changes_status() {
changes="$staged_changes$conflicted_changes$unstaged_changes$untracked_changes"
fi
- printf $PRINT_F_OPTION "$changes"
+ printf $PRINT_F_OPTION "${changes:1}"
}
bash_color_changes_status() {
@@ -409,8 +421,6 @@ zsh_color_changes_status() {
}
color_local_commits() {
- local separator="${1:- }"
-
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"
@@ -421,11 +431,11 @@ color_local_commits() {
local_behind="$(commits_behind_of_remote "$remote_branch")"
if [[ "$local_behind" -gt "0" && "$local_ahead" -gt "0" ]]; then
- local_commits="$separator$local_behind$yellow_diverged_arrow$local_ahead"
+ local_commits="$local_behind$yellow_diverged_arrow$local_ahead"
elif [[ "$local_behind" -gt "0" ]]; then
- local_commits="$separator$local_behind$red_behind_arrow"
+ local_commits="$local_behind$red_behind_arrow"
elif [[ "$local_ahead" -gt "0" ]]; then
- local_commits="$separator$local_ahead$green_ahead_arrow"
+ local_commits="$local_ahead$green_ahead_arrow"
fi
fi
printf $PRINT_F_OPTION "$local_commits"
@@ -450,14 +460,14 @@ color_remote_commits() {
remote_behind="$(remote_behind_of_master "$remote_branch")"
if [[ "$remote_behind" -gt "0" && "$remote_ahead" -gt "0" ]]; then
- remote="$MASTER_SYMBOL $remote_behind $yellow_diverged_arrow $remote_ahead "
+ remote="$MASTER_SYMBOL $remote_behind $yellow_diverged_arrow $remote_ahead"
elif [[ "$remote_ahead" -gt "0" ]]; then
- remote="$MASTER_SYMBOL $green_ahead_arrow $remote_ahead "
+ remote="$MASTER_SYMBOL $green_ahead_arrow $remote_ahead"
elif [[ "$remote_behind" -gt "0" ]]; then
- remote="$MASTER_SYMBOL $remote_behind $red_behind_arrow "
+ remote="$MASTER_SYMBOL $remote_behind $red_behind_arrow"
fi
else
- remote="upstream $not_upstream "
+ remote="upstream $not_upstream"
fi
printf $PRINT_F_OPTION "$remote"
@@ -493,12 +503,75 @@ show_remote_status() {
}
stashed_status() {
- printf '%s' "$(git stash list | wc -l 2>/dev/null)"
+ printf '%s' "$(git stash list | wc -l 2>/dev/null | grep -oEi '[0-9][0-9]*')"
}
stash_status() {
local number_stashes="$(stashed_status)"
if [ $number_stashes -gt 0 ]; then
- printf $PRINT_F_OPTION " $number_stashes$COLOR_STASH≡$RESET_COLOR_STASH"
+ printf $PRINT_F_OPTION "$number_stashes$COLOR_STASH≡$RESET_COLOR_STASH"
+ fi
+}
+
+render_prompt() {
+ output="$PROMPT_FORMAT"
+ branch_sed=""
+ remote_sed=""
+ local_sed=""
+ changes_sed=""
+ stash_sed=""
+
+
+ if_pre="%\{([^%{}]{1,}:){0,1}"
+ if_post="(:[^%{}]{1,}){0,1}\}"
+ sed_pre="%{\(\([^%^{^}]*\)\:\)\{0,1\}"
+ sed_post="\(\:\([^%^{^}]*\)\)\{0,1\}}"
+
+ if [[ $output =~ ${if_pre}remote${if_post} ]]; then
+ remote_result="$(color_remote_commits)"
+ if [[ -n "$remote_result" ]]; then
+ remote_sed="s/${sed_pre}remote${sed_post}/\2${remote_result}\4/"
+ else
+ remote_sed="s/${sed_pre}remote${sed_post}//"
+ fi
fi
+ if [[ $PROMPT_FORMAT =~ ${if_pre}branch${if_post} ]]; then
+ branch_result="$(readable_branch_name | sed -e 's/\//\\\//')"
+ if [[ -n "$branch_result" ]]; then
+ branch_sed="s/${sed_pre}branch${sed_post}/\2${branch_result}\4/"
+ else
+ branch_sed="s/${sed_pre}branch${sed_post}//"
+ fi
+ fi
+ if [[ $PROMPT_FORMAT =~ ${if_pre}local${if_post} ]]; then
+ local_result="$(color_local_commits)"
+ if [[ -n "$local_result" ]]; then
+ local_sed="s/${sed_pre}local${sed_post}/\2$local_result\4/"
+ else
+ local_sed="s/${sed_pre}local${sed_post}//"
+ fi
+ fi
+ if [[ $PROMPT_FORMAT =~ ${if_pre}changes${if_post} ]]; then
+ changes_result="$(color_changes_status)"
+ if [[ -n "$changes_result" ]]; then
+ changes_sed="s/${sed_pre}changes${sed_post}/\2${changes_result}\4/"
+ else
+ changes_sed="s/${sed_pre}changes${sed_post}//"
+ fi
+ fi
+ if [[ $PROMPT_FORMAT =~ ${if_pre}stash${if_post} ]]; then
+ stash_result="$(stash_status)"
+ if [[ -n "$stash_result" ]]; then
+ stash_sed="s/${sed_pre}stash${sed_post}/\2${stash_result}\4/"
+ else
+ stash_sed="s/${sed_pre}stash${sed_post}//"
+ fi
+ fi
+
+ printf '%b' "$output" | sed \
+ -e "$remote_sed" \
+ -e "$branch_sed" \
+ -e "$changes_sed" \
+ -e "$local_sed" \
+ -e "$stash_sed"
}