diff options
author | Michael Allen <michael@michaelallen.io> | 2015-09-15 10:04:15 +0100 |
---|---|---|
committer | Michael Allen <michael@michaelallen.io> | 2015-09-16 15:37:05 +0100 |
commit | 5c68ecdd5d388a4a5604c0f377c4b917eb0dcfff (patch) | |
tree | 417543323650f283428ff2f926fc73a906127ee6 | |
parent | 8c682d2abddd006398e9aed0a61212b4648b5a59 (diff) | |
download | git-sonar-5c68ecdd5d388a4a5604c0f377c4b917eb0dcfff.tar.gz git-sonar-5c68ecdd5d388a4a5604c0f377c4b917eb0dcfff.zip |
Make render replace rather than append, so we can reorder
-rwxr-xr-x | radar-base.sh | 21 | ||||
-rwxr-xr-x | test | 1 | ||||
-rwxr-xr-x | test-format-config.sh | 27 |
3 files changed, 44 insertions, 5 deletions
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" } @@ -7,3 +7,4 @@ ./test-files.sh ./test-status.sh ./test-colors.sh +./test-format-config.sh diff --git a/test-format-config.sh b/test-format-config.sh index 17c4bd6..e595703 100755 --- a/test-format-config.sh +++ b/test-format-config.sh @@ -108,4 +108,31 @@ test_all_options_set_config() { rm_tmp } +test_reorder_parts() { + prepare_test_repo + + export GIT_RADAR_FORMAT="%{branch}%{local}%{changes}%{remote}" + prepare_zsh_colors + unset_colours + + prompt="$(render_prompt)" + assertEquals "foo 1↑ 1Am 1 → " "$prompt" + + export GIT_RADAR_FORMAT="%{local}%{changes}%{remote}%{branch}" + prepare_zsh_colors + unset_colours + + prompt="$(render_prompt)" + assertEquals " 1↑ 1Am 1 → foo" "$prompt" + + export GIT_RADAR_FORMAT="%{changes}%{remote}%{branch}%{local}" + prepare_zsh_colors + unset_colours + + prompt="$(render_prompt)" + assertEquals " 1Am 1 → foo 1↑" "$prompt" + + rm_tmp +} + . ./shunit/shunit2 |