mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-15 09:58:47 -07:00
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.
This commit is contained in:
parent
8e10ac4d73
commit
62216aaa8f
@ -91,22 +91,23 @@ export ZSH=\"$ZSH\"
|
|||||||
}
|
}
|
||||||
|
|
||||||
setup_shell() {
|
setup_shell() {
|
||||||
# If this user's login shell is not already "zsh", attempt to switch.
|
# If this user's login shell is already "zsh", do not attempt to switch.
|
||||||
TEST_CURRENT_SHELL=$(basename "$SHELL")
|
if [ "$(basename "$SHELL")" = "zsh" ]; then
|
||||||
if [ "$TEST_CURRENT_SHELL" != "zsh" ]; then
|
return
|
||||||
# If this platform provides a "chsh" command (not Cygwin), do it, man!
|
fi
|
||||||
if command_exists chsh; then
|
|
||||||
echo "${BLUE}Time to change your default shell to zsh!${NORMAL}"
|
# If this platform doesn't provide a "chsh" command, bail out.
|
||||||
if ! chsh -s $(grep '^/.*/zsh$' /etc/shells | tail -1); then
|
if ! command_exists chsh; then
|
||||||
error "chsh command unsuccessful. Change your default shell manually."
|
cat <<-EOF
|
||||||
fi
|
I can't change your shell automatically because this system does not have chsh.
|
||||||
# Else, suggest the user do so manually.
|
${BLUE}Please manually change your default shell to zsh${NORMAL}
|
||||||
else
|
EOF
|
||||||
cat <<-EOF
|
return
|
||||||
I can't change your shell automatically because this system does not have chsh.
|
fi
|
||||||
${BLUE}Please manually change your default shell to zsh${NORMAL}
|
|
||||||
EOF
|
echo "${BLUE}Time to change your default shell to zsh!${NORMAL}"
|
||||||
fi
|
if ! chsh -s $(grep '^/.*/zsh$' /etc/shells | tail -1); then
|
||||||
|
error "chsh command unsuccessful. Change your default shell manually."
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user