From 9cfc2ed7f46fa9dea9fbeeef51a8ea8883c41c59 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Wed, 16 Sep 2015 14:21:43 +0100 Subject: Merge bash and zsh specific render functions --- radar-base.sh | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'radar-base.sh') diff --git a/radar-base.sh b/radar-base.sh index 2ad9ce7..12cab90 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -12,6 +12,8 @@ prepare_bash_colors() { 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" @@ -42,6 +44,8 @@ prepare_zsh_colors() { 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]}%}" @@ -398,7 +402,7 @@ 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() { @@ -430,7 +434,7 @@ zsh_color_changes_status() { changes="$staged_changes$conflicted_changes$unstaged_changes$untracked_changes" fi - printf %s "$changes" + printf $PRINT_F_OPTION "$changes" } bash_color_local_commits() { @@ -453,7 +457,7 @@ 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() { @@ -476,7 +480,7 @@ zsh_color_local_commits() { local_commits="$separator$local_ahead$ahead_arrow" fi fi - printf %s "$local_commits" + printf $PRINT_F_OPTION "$local_commits" } bash_color_remote_commits() { @@ -500,7 +504,7 @@ bash_color_remote_commits() { remote="upstream $not_upstream " fi - printf "$remote" + printf $PRINT_F_OPTION "$remote" } zsh_color_remote_commits() { @@ -524,7 +528,7 @@ zsh_color_remote_commits() { remote="upstream $not_upstream " fi - printf %s "$remote" + printf $PRINT_F_OPTION "$remote" } show_remote_status() { if [[ $@ == *$NO_REMOTE_STATUS* ]]; then -- cgit v1.2.3 From 1285baa3c095962265dc07b515ac9c0f7e75b959 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Wed, 16 Sep 2015 14:24:29 +0100 Subject: Merge zsh and bash remote commit diff --- radar-base.sh | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) (limited to 'radar-base.sh') diff --git a/radar-base.sh b/radar-base.sh index 12cab90..747cb5e 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -483,7 +483,7 @@ zsh_color_local_commits() { printf $PRINT_F_OPTION "$local_commits" } -bash_color_remote_commits() { +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" @@ -507,29 +507,14 @@ bash_color_remote_commits() { printf $PRINT_F_OPTION "$remote" } -zsh_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="$MASTER_SYMBOL $remote_behind $yellow_diverged_arrow $remote_ahead " - elif [[ "$remote_ahead" -gt "0" ]]; then - remote="$MASTER_SYMBOL $green_ahead_arrow $remote_ahead " - elif [[ "$remote_behind" -gt "0" ]]; then - remote="$MASTER_SYMBOL $remote_behind $red_behind_arrow " - fi - else - remote="upstream $not_upstream " - fi +bash_color_remote_commits() { + color_remote_commits +} - printf $PRINT_F_OPTION "$remote" +zsh_color_remote_commits() { + color_remote_commits } + show_remote_status() { if [[ $@ == *$NO_REMOTE_STATUS* ]]; then return 1 # don't show the git remote status -- cgit v1.2.3 From d4ce9372c1f5ee82ac019d5a3c84f8af64cb0e4f Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Wed, 16 Sep 2015 14:26:27 +0100 Subject: Merge zsh and bash local commit render func --- radar-base.sh | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) (limited to 'radar-base.sh') diff --git a/radar-base.sh b/radar-base.sh index 747cb5e..fb5fa90 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -437,7 +437,7 @@ zsh_color_changes_status() { printf $PRINT_F_OPTION "$changes" } -bash_color_local_commits() { +color_local_commits() { local separator="${1:- }" local green_ahead_arrow="${COLOR_LOCAL_AHEAD}↑$RESET_COLOR_LOCAL" @@ -460,27 +460,12 @@ bash_color_local_commits() { printf $PRINT_F_OPTION "$local_commits" } -zsh_color_local_commits() { - local separator="${1:- }" - - local ahead_arrow="${COLOR_LOCAL_AHEAD}↑$RESET_COLOR_LOCAL" - local behind_arrow="${COLOR_LOCAL_BEHIND}↓$RESET_COLOR_LOCAL" - local diverged_arrow="${COLOR_LOCAL_DIVERGED}⇵$RESET_COLOR_LOCAL" - - 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 $PRINT_F_OPTION "$local_commits" +zsh_color_local_commits() { + color_local_commits } color_remote_commits() { -- cgit v1.2.3 From 223312b3ce46caaabb233d03722d6393e9631706 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Wed, 16 Sep 2015 14:28:19 +0100 Subject: Merge the zsh/bash changes render function --- radar-base.sh | 36 ++++++------------------------------ 1 file changed, 6 insertions(+), 30 deletions(-) (limited to 'radar-base.sh') diff --git a/radar-base.sh b/radar-base.sh index fb5fa90..a4c67a1 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -373,7 +373,7 @@ untracked_status() { printf '%s' "$untracked_string" } -bash_color_changes_status() { +color_changes_status() { local separator="${1:- }" local porcelain="$(porcelain_status)" @@ -405,36 +405,12 @@ bash_color_changes_status() { printf $PRINT_F_OPTION "$changes" } -zsh_color_changes_status() { - local separator="${1:- }" - - local porcelain="$(porcelain_status)" - local changes="" - - if [[ -n "$porcelain" ]]; then - 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 - - 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 $PRINT_F_OPTION "$changes" +zsh_color_changes_status() { + color_changes_status } color_local_commits() { -- cgit v1.2.3 From 2c0be1e2fd311a5fd18726b44be1a0ff8ae823e4 Mon Sep 17 00:00:00 2001 From: Michael Allen Date: Wed, 16 Sep 2015 14:31:23 +0100 Subject: Merge the zsh/bash readable branch function --- radar-base.sh | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'radar-base.sh') diff --git a/radar-base.sh b/radar-base.sh index a4c67a1..d9cd8f5 100755 --- a/radar-base.sh +++ b/radar-base.sh @@ -184,18 +184,6 @@ branch_ref() { fi } -zsh_readable_branch_name() { - if is_repo; then - printf '%s' "$COLOR_BRANCH$(branch_name || printf '%s' "detached@$(commit_short_sha)")$RESET_COLOR_BRANCH" - fi -} - -bash_readable_branch_name() { - if is_repo; then - printf "$COLOR_BRANCH$(branch_name || printf '%s' "detached@$(commit_short_sha)")$RESET_COLOR_BRANCH" - fi -} - remote_branch_name() { local localRef="\/$(branch_name)$" if [[ -n "$localRef" ]]; then @@ -476,6 +464,20 @@ zsh_color_remote_commits() { color_remote_commits } +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 +} + +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 -- cgit v1.2.3