62216aaa8ff496cd1a086c70642b5fff9e7fa282

Author
Marc Cornellà <marc.cornella@live.com>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

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.

Diff

 1diff --git a/tools/install.sh b/tools/install.sh
 2index 7eea2e748788a019a289294231f2a44a36998f94..4dc25b0e0f34ec540ae418c82668b52a16b0e70e 100755
 3--- a/tools/install.sh
 4+++ b/tools/install.sh
 5@@ -91,22 +91,23 @@ export ZSH=\"$ZSH\"
 6 }
 7 
 8 setup_shell() {
 9-	# If this user's login shell is not already "zsh", attempt to switch.
10-	TEST_CURRENT_SHELL=$(basename "$SHELL")
11-	if [ "$TEST_CURRENT_SHELL" != "zsh" ]; then
12-		# If this platform provides a "chsh" command (not Cygwin), do it, man!
13-		if command_exists chsh; then
14-			echo "${BLUE}Time to change your default shell to zsh!${NORMAL}"
15-			if ! chsh -s $(grep '^/.*/zsh$' /etc/shells | tail -1); then
16-				error "chsh command unsuccessful. Change your default shell manually."
17-			fi
18-		# Else, suggest the user do so manually.
19-		else
20-			cat <<-EOF
21-				I can't change your shell automatically because this system does not have chsh.
22-				${BLUE}Please manually change your default shell to zsh${NORMAL}
23-			EOF
24-		fi
25+	# If this user's login shell is already "zsh", do not attempt to switch.
26+	if [ "$(basename "$SHELL")" = "zsh" ]; then
27+		return
28+	fi
29+
30+	# If this platform doesn't provide a "chsh" command, bail out.
31+	if ! command_exists chsh; then
32+		cat <<-EOF
33+			I can't change your shell automatically because this system does not have chsh.
34+			${BLUE}Please manually change your default shell to zsh${NORMAL}
35+		EOF
36+		return
37+	fi
38+
39+	echo "${BLUE}Time to change your default shell to zsh!${NORMAL}"
40+	if ! chsh -s $(grep '^/.*/zsh$' /etc/shells | tail -1); then
41+		error "chsh command unsuccessful. Change your default shell manually."
42 	fi
43 }
44