From 3eb5e037f940861f20cda1d0b5cb7dda4c5f8f22 Mon Sep 17 00:00:00 2001 From: Ethan Edwards Date: Tue, 6 Feb 2018 03:32:08 -0600 Subject: [PATCH 1/4] GH-1140 add safe usage of SCM variable --- themes/base.theme.bash | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index a18c3729..f9144e54 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -79,10 +79,10 @@ function scm { } function scm_prompt_char { - if [[ -z $SCM ]]; then scm; fi - if [[ $SCM == $SCM_GIT ]]; then SCM_CHAR=$SCM_GIT_CHAR - elif [[ $SCM == $SCM_HG ]]; then SCM_CHAR=$SCM_HG_CHAR - elif [[ $SCM == $SCM_SVN ]]; then SCM_CHAR=$SCM_SVN_CHAR + if [[ -z ${SCM:-} ]]; then scm; fi + if [[ ${SCM:-} == $SCM_GIT ]]; then SCM_CHAR=$SCM_GIT_CHAR + elif [[ ${SCM:-} == $SCM_HG ]]; then SCM_CHAR=$SCM_HG_CHAR + elif [[ ${SCM:-} == $SCM_SVN ]]; then SCM_CHAR=$SCM_SVN_CHAR else SCM_CHAR=$SCM_NONE_CHAR fi } @@ -92,9 +92,9 @@ function scm_prompt_vars { scm_prompt_char SCM_DIRTY=0 SCM_STATE='' - [[ $SCM == $SCM_GIT ]] && git_prompt_vars && return - [[ $SCM == $SCM_HG ]] && hg_prompt_vars && return - [[ $SCM == $SCM_SVN ]] && svn_prompt_vars && return + [[ ${SCM:-} == $SCM_GIT ]] && git_prompt_vars && return + [[ ${SCM:-} == $SCM_HG ]] && hg_prompt_vars && return + [[ ${SCM:-} == $SCM_SVN ]] && svn_prompt_vars && return } function scm_prompt_info { @@ -113,7 +113,7 @@ function scm_prompt_info_common { SCM_DIRTY=0 SCM_STATE='' - if [[ ${SCM} == ${SCM_GIT} ]]; then + if [[ ${SCM:-} == ${SCM_GIT} ]]; then if [[ ${SCM_GIT_SHOW_MINIMAL_INFO} == true ]]; then # user requests minimal git status information git_prompt_minimal_info @@ -125,8 +125,8 @@ function scm_prompt_info_common { fi # TODO: consider adding minimal status information for hg and svn - [[ ${SCM} == ${SCM_HG} ]] && hg_prompt_info && return - [[ ${SCM} == ${SCM_SVN} ]] && svn_prompt_info && return + [[ ${SCM:-} == ${SCM_HG} ]] && hg_prompt_info && return + [[ ${SCM:-} == ${SCM_SVN} ]] && svn_prompt_info && return } function git_prompt_minimal_info { From f5c483cfaae9721bae5070e4d5eea571ccab921e Mon Sep 17 00:00:00 2001 From: Ethan Edwards Date: Tue, 6 Feb 2018 11:27:28 -0600 Subject: [PATCH 2/4] GH-1140 add additional uninitialized variable coverage --- themes/githelpers.theme.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/githelpers.theme.bash b/themes/githelpers.theme.bash index e6bda810..66279faf 100644 --- a/themes/githelpers.theme.bash +++ b/themes/githelpers.theme.bash @@ -72,7 +72,7 @@ function _git-hide-status { function _git-status { [[ "${SCM_GIT_IGNORE_UNTRACKED}" = "true" ]] && local git_status_flags='-uno' - git status --porcelain ${git_status_flags} 2> /dev/null + git status --porcelain ${git_status_flags:-} 2> /dev/null } function _git-status-counts { From 1a7ebf4da70b0fbcb6ec5d5e3da88f884c65d356 Mon Sep 17 00:00:00 2001 From: Ethan Edwards Date: Mon, 30 Apr 2018 13:40:08 -0500 Subject: [PATCH 3/4] change to setting variables to empty value before use --- themes/base.theme.bash | 6 +++++- themes/githelpers.theme.bash | 6 ++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 2cc41643..12df1d8a 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -7,6 +7,8 @@ CLOCK_THEME_PROMPT_SUFFIX='' THEME_PROMPT_HOST='\H' +SCM= + SCM_CHECK=${SCM_CHECK:=true} SCM_THEME_PROMPT_DIRTY=' ✗' @@ -64,6 +66,8 @@ THEME_SHOW_USER_HOST=${THEME_SHOW_USER_HOST:=false} USER_HOST_THEME_PROMPT_PREFIX='' USER_HOST_THEME_PROMPT_SUFFIX='' +VIRTUAL_ENV= + VIRTUALENV_THEME_PROMPT_PREFIX=' |' VIRTUALENV_THEME_PROMPT_SUFFIX='|' @@ -122,7 +126,7 @@ function scm_prompt_info_common { SCM_DIRTY=0 SCM_STATE='' - if [[ ${SCM:-} == ${SCM_GIT} ]]; then + if [[ ${SCM} == ${SCM_GIT} ]]; then if [[ ${SCM_GIT_SHOW_MINIMAL_INFO} == true ]]; then # user requests minimal git status information git_prompt_minimal_info diff --git a/themes/githelpers.theme.bash b/themes/githelpers.theme.bash index 66279faf..833e5190 100644 --- a/themes/githelpers.theme.bash +++ b/themes/githelpers.theme.bash @@ -71,7 +71,8 @@ function _git-hide-status { } function _git-status { - [[ "${SCM_GIT_IGNORE_UNTRACKED}" = "true" ]] && local git_status_flags='-uno' + local git_status_flags= + [[ "${SCM_GIT_IGNORE_UNTRACKED}" = "true" ]] && git_status_flags='-uno' git status --porcelain ${git_status_flags:-} 2> /dev/null } @@ -102,7 +103,8 @@ function _git-status-counts { function _git-remote-info { [[ "$(_git-upstream)" == "" ]] && return - [[ "$(_git-branch)" == "$(_git-upstream-branch)" ]] && local same_branch_name=true + local same_branch_name= + [[ "$(_git-branch)" == "$(_git-upstream-branch)" ]] && same_branch_name=true if ([[ "${SCM_GIT_SHOW_REMOTE_INFO}" = "auto" ]] && [[ "$(_git-num-remotes)" -ge 2 ]]) || [[ "${SCM_GIT_SHOW_REMOTE_INFO}" = "true" ]]; then if [[ "${same_branch_name}" != "true" ]]; then From 3bb21ba1e9feaa90aebde84fd550575801aa694f Mon Sep 17 00:00:00 2001 From: Ethan Edwards Date: Mon, 30 Apr 2018 13:43:16 -0500 Subject: [PATCH 4/4] removed unneeded default value --- themes/githelpers.theme.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/githelpers.theme.bash b/themes/githelpers.theme.bash index 833e5190..1f43382d 100644 --- a/themes/githelpers.theme.bash +++ b/themes/githelpers.theme.bash @@ -73,7 +73,7 @@ function _git-hide-status { function _git-status { local git_status_flags= [[ "${SCM_GIT_IGNORE_UNTRACKED}" = "true" ]] && git_status_flags='-uno' - git status --porcelain ${git_status_flags:-} 2> /dev/null + git status --porcelain ${git_status_flags} 2> /dev/null } function _git-status-counts {