summaryrefslogtreecommitdiffstats
path: root/radar-base.sh
diff options
context:
space:
mode:
Diffstat (limited to 'radar-base.sh')
-rwxr-xr-xradar-base.sh83
1 files changed, 73 insertions, 10 deletions
diff --git a/radar-base.sh b/radar-base.sh
index d9cd8f5..258e5b1 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"
@@ -31,6 +39,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%{ :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"
@@ -65,6 +75,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%}%{ :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}%}"
@@ -390,7 +402,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() {
@@ -402,8 +414,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"
@@ -414,11 +424,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"
@@ -443,14 +453,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"
@@ -484,3 +494,56 @@ show_remote_status() {
fi
return 0
}
+
+render_prompt() {
+ output="$PROMPT_FORMAT"
+ branch_sed=""
+ remote_sed=""
+ local_sed=""
+ changes_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
+
+ printf '%b' "$output" | sed \
+ -e "$remote_sed" \
+ -e "$branch_sed" \
+ -e "$changes_sed" \
+ -e "$local_sed"
+}