From 12e225afefbe77a2fa478f9fb0425d353b5a4cc0 Mon Sep 17 00:00:00 2001 From: terminalforlife Date: Wed, 17 Feb 2021 21:23:29 +0000 Subject: [PATCH] Tweak logic & slightly optimize git usage This sort of test: ```sh if CONDITION; then if CONDITION; then LIST fi fi ``` The above is typically unnecessary, as the two conditions can be combined to avoid pointless nesting. Regarding the optimization: it's very minor, but there was an unnecessary use of a subshell (command substitution) in testing this: ``` git rev-parse --is-inside-work-tree ``` This has been addressed, and instead of STDERR going to '/dev/null', - now both STDOUT and STDERR do. Although I'm pointing out this in just one instance, this sort of stuff appears to be all over the code in this project, unfortunately. --- themes/base.theme.bash | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 30305957..64d5c888 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -104,7 +104,7 @@ function scm { SCM=$SCM_NONE elif [[ -f .git/HEAD ]] && [[ -x "$GIT_EXE" ]]; then SCM=$SCM_GIT - elif [[ -x "$GIT_EXE" ]] && [[ -n "$(git rev-parse --is-inside-work-tree 2> /dev/null)" ]]; then + elif [[ -x "$GIT_EXE" ]] && git rev-parse --is-inside-work-tree &> /dev/null; then SCM=$SCM_GIT elif [[ -x "$P4_EXE" ]] && [[ -n "$(p4 set P4CLIENT 2> /dev/null)" ]]; then SCM=$SCM_P4 @@ -181,10 +181,8 @@ function scm_prompt_info_common { } function terraform_workspace_prompt { - if _command_exists terraform; then - if [ -d .terraform ]; then - echo -e "$(terraform workspace show 2> /dev/null)" - fi + if _command_exists terraform && [ -d .terraform ]; then + echo -e "$(terraform workspace show 2> /dev/null)" fi }