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