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.
pull/1840/head
terminalforlife 2021-02-17 21:23:29 +00:00
parent 4607ee7452
commit 12e225afef
1 changed files with 3 additions and 5 deletions

View File

@ -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
}