summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorMarc Cornellà <marc.cornella@live.com>2019-05-24 16:17:09 +0200
committerMarc Cornellà <marc.cornella@live.com>2019-06-03 17:18:23 +0200
commit62216aaa8ff496cd1a086c70642b5fff9e7fa282 (patch)
tree1cd6731db2c3ec698f1ce2569a991b4ae3c83405 /tools
parent8e10ac4d7346ebd4c6cf2815b72fd82c1cf980a0 (diff)
downloadzsh-62216aaa8ff496cd1a086c70642b5fff9e7fa282.tar.gz
zsh-62216aaa8ff496cd1a086c70642b5fff9e7fa282.tar.bz2
zsh-62216aaa8ff496cd1a086c70642b5fff9e7fa282.zip
installer: use guard clauses in setup_shell for better readability
Guard clauses are if constructs that return early if there is an error that prevents continuing. This way there isn't a big nesting of if expressions.
Diffstat (limited to 'tools')
-rwxr-xr-xtools/install.sh33
1 files changed, 17 insertions, 16 deletions
diff --git a/tools/install.sh b/tools/install.sh
index 7eea2e748..4dc25b0e0 100755
--- a/tools/install.sh
+++ b/tools/install.sh
@@ -91,22 +91,23 @@ export ZSH=\"$ZSH\"
}
setup_shell() {
- # If this user's login shell is not already "zsh", attempt to switch.
- TEST_CURRENT_SHELL=$(basename "$SHELL")
- if [ "$TEST_CURRENT_SHELL" != "zsh" ]; then
- # If this platform provides a "chsh" command (not Cygwin), do it, man!
- if command_exists chsh; then
- echo "${BLUE}Time to change your default shell to zsh!${NORMAL}"
- if ! chsh -s $(grep '^/.*/zsh$' /etc/shells | tail -1); then
- error "chsh command unsuccessful. Change your default shell manually."
- fi
- # Else, suggest the user do so manually.
- else
- cat <<-EOF
- I can't change your shell automatically because this system does not have chsh.
- ${BLUE}Please manually change your default shell to zsh${NORMAL}
- EOF
- fi
+ # If this user's login shell is already "zsh", do not attempt to switch.
+ if [ "$(basename "$SHELL")" = "zsh" ]; then
+ return
+ fi
+
+ # If this platform doesn't provide a "chsh" command, bail out.
+ if ! command_exists chsh; then
+ cat <<-EOF
+ I can't change your shell automatically because this system does not have chsh.
+ ${BLUE}Please manually change your default shell to zsh${NORMAL}
+ EOF
+ return
+ fi
+
+ echo "${BLUE}Time to change your default shell to zsh!${NORMAL}"
+ if ! chsh -s $(grep '^/.*/zsh$' /etc/shells | tail -1); then
+ error "chsh command unsuccessful. Change your default shell manually."
fi
}