From 8c682d2abddd006398e9aed0a61212b4648b5a59 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Mon, 14 Sep 2015 17:22:01 +0100 Subject: Basic approach to format strings --- radar-base.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'radar-base.sh') diff --git a/radar-base.sh b/radar-base.sh index d9cd8f5..e21122a 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -65,6 +65,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:-""}" + 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}%}" @@ -484,3 +486,18 @@ show_remote_status() { fi return 0 } + +render_prompt() { + if [[ $PROMPT_FORMAT =~ ^.*%{remote}.*$ ]]; then + zsh_color_remote_commits + fi + if [[ $PROMPT_FORMAT =~ ^.*%{branch}.*$ ]]; then + zsh_readable_branch_name + fi + if [[ $PROMPT_FORMAT =~ ^.*%{local}.*$ ]]; then + zsh_color_local_commits + fi + if [[ $PROMPT_FORMAT =~ ^.*%{changes}.*$ ]]; then + zsh_color_changes_status + fi +} -- cgit v1.2.3 From 5c68ecdd5d388a4a5604c0f377c4b917eb0dcfff Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Tue, 15 Sep 2015 10:04:15 +0100 Subject: Make render replace rather than append, so we can reorder --- radar-base.sh | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'radar-base.sh') diff --git a/radar-base.sh b/radar-base.sh index e21122a..066da99 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -488,16 +488,27 @@ show_remote_status() { } render_prompt() { - if [[ $PROMPT_FORMAT =~ ^.*%{remote}.*$ ]]; then - zsh_color_remote_commits + output="$PROMPT_FORMAT" + branch_sed="" + remote_sed="" + local_sed="" + changes_sed="" + if [[ $output =~ ^.*%{remote}.*$ ]]; then + remote_sed="s/%{remote}/$(zsh_color_remote_commits)/" fi if [[ $PROMPT_FORMAT =~ ^.*%{branch}.*$ ]]; then - zsh_readable_branch_name + branch_sed="s/%{branch}/$(zsh_readable_branch_name)/" fi if [[ $PROMPT_FORMAT =~ ^.*%{local}.*$ ]]; then - zsh_color_local_commits + local_sed="s/%{local}/$(zsh_color_local_commits)/" fi if [[ $PROMPT_FORMAT =~ ^.*%{changes}.*$ ]]; then - zsh_color_changes_status + changes_sed="s/%{changes}/$(zsh_color_changes_status)/" fi + + sed \ + -e "$remote_sed" \ + -e "$branch_sed" \ + -e "$changes_sed" \ + -e "$local_sed" <<<"$output" } -- cgit v1.2.3 From 6b6467dd66d7d8bd7b2ac357063876f9bed3a3cb Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Wed, 16 Sep 2015 15:37:41 +0100 Subject: Use general render functions rather than zsh specific --- radar-base.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'radar-base.sh') diff --git a/radar-base.sh b/radar-base.sh index 066da99..b7231de 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -494,16 +494,16 @@ render_prompt() { local_sed="" changes_sed="" if [[ $output =~ ^.*%{remote}.*$ ]]; then - remote_sed="s/%{remote}/$(zsh_color_remote_commits)/" + remote_sed="s/%{remote}/$(color_remote_commits)/" fi if [[ $PROMPT_FORMAT =~ ^.*%{branch}.*$ ]]; then - branch_sed="s/%{branch}/$(zsh_readable_branch_name)/" + branch_sed="s/%{branch}/$(readable_branch_name)/" fi if [[ $PROMPT_FORMAT =~ ^.*%{local}.*$ ]]; then - local_sed="s/%{local}/$(zsh_color_local_commits)/" + local_sed="s/%{local}/$(color_local_commits)/" fi if [[ $PROMPT_FORMAT =~ ^.*%{changes}.*$ ]]; then - changes_sed="s/%{changes}/$(zsh_color_changes_status)/" + changes_sed="s/%{changes}/$(color_changes_status)/" fi sed \ -- cgit v1.2.3 From 5d2bded520a2649a3cc19b6c767fa23d9b00555e Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Thu, 17 Sep 2015 09:45:57 +0100 Subject: Make providing a prefix and suffix to changes possible --- radar-base.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'radar-base.sh') diff --git a/radar-base.sh b/radar-base.sh index b7231de..6458446 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -502,8 +502,8 @@ render_prompt() { if [[ $PROMPT_FORMAT =~ ^.*%{local}.*$ ]]; then local_sed="s/%{local}/$(color_local_commits)/" fi - if [[ $PROMPT_FORMAT =~ ^.*%{changes}.*$ ]]; then - changes_sed="s/%{changes}/$(color_changes_status)/" + if [[ $PROMPT_FORMAT =~ %{([^%{}]{1,}:){0,1}changes(:[^%{}]{1,}){0,1}} ]]; then + changes_sed="s/%{\(\([^%^{^}]*\)\:\)\{0,1\}changes\(\:\([^%^{^}]*\)\)\{0,1\}}/\2$(color_changes_status)\4/" fi sed \ -- cgit v1.2.3 From 3e809c83741cc6466090169404dd0aa2672d29ac Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Thu, 17 Sep 2015 10:40:06 +0100 Subject: Add prefix/suffixing to local diff --- radar-base.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'radar-base.sh') diff --git a/radar-base.sh b/radar-base.sh index 6458446..665b30a 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -499,8 +499,8 @@ render_prompt() { if [[ $PROMPT_FORMAT =~ ^.*%{branch}.*$ ]]; then branch_sed="s/%{branch}/$(readable_branch_name)/" fi - if [[ $PROMPT_FORMAT =~ ^.*%{local}.*$ ]]; then - local_sed="s/%{local}/$(color_local_commits)/" + if [[ $PROMPT_FORMAT =~ %{([^%{}]{1,}:){0,1}local(:[^%{}]{1,}){0,1}} ]]; then + local_sed="s/%{\(\([^%^{^}]*\)\:\)\{0,1\}local\(\:\([^%^{^}]*\)\)\{0,1\}}/\2$(color_local_commits)\4/" fi if [[ $PROMPT_FORMAT =~ %{([^%{}]{1,}:){0,1}changes(:[^%{}]{1,}){0,1}} ]]; then changes_sed="s/%{\(\([^%^{^}]*\)\:\)\{0,1\}changes\(\:\([^%^{^}]*\)\)\{0,1\}}/\2$(color_changes_status)\4/" -- cgit v1.2.3 From 01bcac0242e4b44c796cdd88c1f87c66c5fdf158 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Thu, 17 Sep 2015 10:46:26 +0100 Subject: Reduce rewording in regexes --- radar-base.sh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'radar-base.sh') diff --git a/radar-base.sh b/radar-base.sh index 665b30a..a1ea097 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -493,17 +493,23 @@ render_prompt() { 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 =~ ^.*%{remote}.*$ ]]; then remote_sed="s/%{remote}/$(color_remote_commits)/" fi if [[ $PROMPT_FORMAT =~ ^.*%{branch}.*$ ]]; then branch_sed="s/%{branch}/$(readable_branch_name)/" fi - if [[ $PROMPT_FORMAT =~ %{([^%{}]{1,}:){0,1}local(:[^%{}]{1,}){0,1}} ]]; then - local_sed="s/%{\(\([^%^{^}]*\)\:\)\{0,1\}local\(\:\([^%^{^}]*\)\)\{0,1\}}/\2$(color_local_commits)\4/" + if [[ $PROMPT_FORMAT =~ ${if_pre}local${if_post} ]]; then + local_sed="s/${sed_pre}local${sed_post}/\2$(color_local_commits)\4/" fi - if [[ $PROMPT_FORMAT =~ %{([^%{}]{1,}:){0,1}changes(:[^%{}]{1,}){0,1}} ]]; then - changes_sed="s/%{\(\([^%^{^}]*\)\:\)\{0,1\}changes\(\:\([^%^{^}]*\)\)\{0,1\}}/\2$(color_changes_status)\4/" + if [[ $PROMPT_FORMAT =~ ${if_pre}changes${if_post} ]]; then + changes_sed="s/${sed_pre}changes${sed_post}/\2$(color_changes_status)\4/" fi sed \ -- cgit v1.2.3 From 7fd5ee18bb412e3ee4db694f551a9b9421e18f89 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Thu, 17 Sep 2015 10:49:37 +0100 Subject: Add prefix and suffix to branch name render --- radar-base.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'radar-base.sh') diff --git a/radar-base.sh b/radar-base.sh index a1ea097..be92bb2 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -502,8 +502,8 @@ render_prompt() { if [[ $output =~ ^.*%{remote}.*$ ]]; then remote_sed="s/%{remote}/$(color_remote_commits)/" fi - if [[ $PROMPT_FORMAT =~ ^.*%{branch}.*$ ]]; then - branch_sed="s/%{branch}/$(readable_branch_name)/" + if [[ $PROMPT_FORMAT =~ ${if_pre}branch${if_post} ]]; then + branch_sed="s/${sed_pre}branch${sed_post}/\2$(readable_branch_name)\4/" fi if [[ $PROMPT_FORMAT =~ ${if_pre}local${if_post} ]]; then local_sed="s/${sed_pre}local${sed_post}/\2$(color_local_commits)\4/" -- cgit v1.2.3 From d2c7ed085ff711a9f34fc1b0f521bcde253f19c5 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Thu, 17 Sep 2015 10:55:09 +0100 Subject: Add prefix and suffixing to remote diff render --- radar-base.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'radar-base.sh') diff --git a/radar-base.sh b/radar-base.sh index be92bb2..9e233ea 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -499,8 +499,8 @@ render_prompt() { sed_pre="%{\(\([^%^{^}]*\)\:\)\{0,1\}" sed_post="\(\:\([^%^{^}]*\)\)\{0,1\}}" - if [[ $output =~ ^.*%{remote}.*$ ]]; then - remote_sed="s/%{remote}/$(color_remote_commits)/" + if [[ $output =~ ${if_pre}remote${if_post} ]]; then + remote_sed="s/${sed_pre}remote${sed_post}/\2$(color_remote_commits)\4/" fi if [[ $PROMPT_FORMAT =~ ${if_pre}branch${if_post} ]]; then branch_sed="s/${sed_pre}branch${sed_post}/\2$(readable_branch_name)\4/" -- cgit v1.2.3 From b4a48dd6b781e357fc513b1f6dd668d8933f3660 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Thu, 17 Sep 2015 11:03:44 +0100 Subject: Switch zsh to use the new render prompt --- radar-base.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'radar-base.sh') diff --git a/radar-base.sh b/radar-base.sh index 9e233ea..8a7faaf 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -65,7 +65,7 @@ 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:-""}" + 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}%}" -- cgit v1.2.3 From 1731759cb2a16a3814d9784bae905250c46ce36b Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Thu, 17 Sep 2015 11:38:03 +0100 Subject: Switch bash to new render function --- radar-base.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'radar-base.sh') diff --git a/radar-base.sh b/radar-base.sh index 8a7faaf..693d763 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -31,6 +31,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" @@ -512,9 +514,9 @@ render_prompt() { changes_sed="s/${sed_pre}changes${sed_post}/\2$(color_changes_status)\4/" fi - sed \ - -e "$remote_sed" \ - -e "$branch_sed" \ - -e "$changes_sed" \ - -e "$local_sed" <<<"$output" + printf '%b' "$output" | sed \ + -e "$remote_sed" \ + -e "$branch_sed" \ + -e "$changes_sed" \ + -e "$local_sed" } -- cgit v1.2.3 From 49d6fcc1190066b38d1684f1cfd1d4fea3190d78 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Thu, 17 Sep 2015 11:52:15 +0100 Subject: Switch local commits to use prefixes --- radar-base.sh | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'radar-base.sh') diff --git a/radar-base.sh b/radar-base.sh index 693d763..b85f75f 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -31,7 +31,7 @@ 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}"}" + 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" @@ -67,7 +67,7 @@ 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}"}" + 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}%}" @@ -406,8 +406,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" @@ -418,11 +416,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" -- cgit v1.2.3 From 06e6a85ebd0d1090128079d0c7e31db43b591d27 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Thu, 17 Sep 2015 14:01:38 +0100 Subject: Switch remote commits to use suffixes --- radar-base.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'radar-base.sh') diff --git a/radar-base.sh b/radar-base.sh index b85f75f..47bcdf7 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -31,7 +31,7 @@ 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}"}" + 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" @@ -67,7 +67,7 @@ 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}"}" + 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}%}" @@ -445,14 +445,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" -- cgit v1.2.3 From 1537438e5798502cad17ba10cf19016e400f7c42 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Thu, 17 Sep 2015 14:08:55 +0100 Subject: Switch changes status to use prefixes --- radar-base.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'radar-base.sh') diff --git a/radar-base.sh b/radar-base.sh index 47bcdf7..054acb7 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -31,7 +31,7 @@ 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}"}" + 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" @@ -67,7 +67,7 @@ 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}"}" + 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}%}" @@ -394,7 +394,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() { -- cgit v1.2.3 From 1d713f471fd77a49bc783ba0b313ebce9de223a5 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Thu, 17 Sep 2015 14:21:38 +0100 Subject: Surround non-printing chars in %{ and %} --- radar-base.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'radar-base.sh') diff --git a/radar-base.sh b/radar-base.sh index 054acb7..f907a0b 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -67,7 +67,7 @@ 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}"}" + 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}%}" -- cgit v1.2.3 From b2590d577d2428264efe2d18f2d50a296d3bcfae Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Thu, 17 Sep 2015 14:44:25 +0100 Subject: Ensure we only render prefix and suffix when we have a result --- radar-base.sh | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'radar-base.sh') diff --git a/radar-base.sh b/radar-base.sh index f907a0b..d5456d0 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -500,16 +500,36 @@ render_prompt() { sed_post="\(\:\([^%^{^}]*\)\)\{0,1\}}" if [[ $output =~ ${if_pre}remote${if_post} ]]; then - remote_sed="s/${sed_pre}remote${sed_post}/\2$(color_remote_commits)\4/" + 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_sed="s/${sed_pre}branch${sed_post}/\2$(readable_branch_name)\4/" + branch_result="$(readable_branch_name)" + 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_sed="s/${sed_pre}local${sed_post}/\2$(color_local_commits)\4/" + 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_sed="s/${sed_pre}changes${sed_post}/\2$(color_changes_status)\4/" + 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 \ -- cgit v1.2.3 From 549734abff2d7cae30b48453687d07212984735f Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Fri, 18 Sep 2015 11:19:35 +0100 Subject: timing function for performance testing --- radar-base.sh | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'radar-base.sh') diff --git a/radar-base.sh b/radar-base.sh index d9cd8f5..92fa205 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" -- cgit v1.2.3 From a2e156cc566ce7ad927eeb203a15aebf73617f2a Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Thu, 15 Oct 2015 11:22:00 +0100 Subject: Fix invalid regex found by @slackorama --- radar-base.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'radar-base.sh') diff --git a/radar-base.sh b/radar-base.sh index 23e3dfd..4f5a483 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -502,8 +502,9 @@ render_prompt() { local_sed="" changes_sed="" - if_pre="%{([^%{}]{1,}:){0,1}" - if_post="(:[^%{}]{1,}){0,1}}" + + if_pre="%\{([^%{}]{1,}:){0,1}" + if_post="(:[^%{}]{1,}){0,1}\}" sed_pre="%{\(\([^%^{^}]*\)\:\)\{0,1\}" sed_post="\(\:\([^%^{^}]*\)\)\{0,1\}}" -- cgit v1.2.3 From 74fb6b46bb581813efb4d55a5b770ba3ca0218f5 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Thu, 15 Oct 2015 11:25:47 +0100 Subject: Support git-flow style branches by @slackorama --- radar-base.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'radar-base.sh') diff --git a/radar-base.sh b/radar-base.sh index 4f5a483..258e5b1 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -517,7 +517,7 @@ render_prompt() { fi fi if [[ $PROMPT_FORMAT =~ ${if_pre}branch${if_post} ]]; then - branch_result="$(readable_branch_name)" + 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 -- cgit v1.2.3 From 51b15bb282dd3c4fc789e2de913ffd561c5debcd Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Fri, 16 Oct 2015 13:49:34 +0100 Subject: Hook new stash_status in to render_prompt --- radar-base.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'radar-base.sh') diff --git a/radar-base.sh b/radar-base.sh index 26ea328..168acf6 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -509,7 +509,7 @@ stashed_status() { 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 } @@ -519,6 +519,7 @@ render_prompt() { remote_sed="" local_sed="" changes_sed="" + stash_sed="" if_pre="%\{([^%{}]{1,}:){0,1}" @@ -558,10 +559,19 @@ render_prompt() { 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 "$local_sed" \ + -e "$stash_sed" } -- cgit v1.2.3 From 6b3360f2a00b55043d2dba574223c6ba77e76580 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Fri, 16 Oct 2015 13:51:15 +0100 Subject: Include stash indicator in default prompt --- radar-base.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'radar-base.sh') diff --git a/radar-base.sh b/radar-base.sh index 168acf6..f3b0d49 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -41,7 +41,7 @@ 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}"}" + 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" @@ -81,7 +81,7 @@ 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}"}" + 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}%}" -- cgit v1.2.3 From 5f5ea03dc57b8aca2a8f8ac938d044dcd110d57a Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Fri, 16 Oct 2015 13:52:54 +0100 Subject: Strip spaces from the stash number (which OSX wc adds for no reason) --- radar-base.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'radar-base.sh') diff --git a/radar-base.sh b/radar-base.sh index f3b0d49..c355f3c 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -503,7 +503,7 @@ 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() { -- cgit v1.2.3