Improvements
- Account for SSH when no input TTY. - Don't exec if no input TTY. - Handle empty passwords.
This commit is contained in:
parent
d6e6a82c5b
commit
4d0fd11293
@ -80,14 +80,12 @@ main() {
|
||||
" ~/.zshrc > ~/.zshrc-omztemp
|
||||
mv -f ~/.zshrc-omztemp ~/.zshrc
|
||||
|
||||
# Do not prompt user unless STDIN file descriptor is bound to TTY,
|
||||
if [ -t 0 ]; then
|
||||
TEST_LOGIN_SHELL=$(expr "$SHELL" : '.*/\(.*\)')
|
||||
if [ "$TEST_LOGIN_SHELL" = "zsh" ]; then
|
||||
# No need to change login shell.
|
||||
ENV_ZSH="$SHELL"
|
||||
# Let's try to change the login shell.
|
||||
else
|
||||
# Let's attempt to change the login shell if the STDIN file descriptor is bound to TTY.
|
||||
elif [ -t 0 ] || [ -p /dev/stdin ]; then
|
||||
# See what zsh (if any) they have in the current environment -- it's probably
|
||||
# the zsh they prefer, assuming /etc/shells could have multiple zsh entries.
|
||||
ENV_ZSH="$(which zsh)" # $(type -P zsh) would be better but not POSIX sh
|
||||
@ -148,6 +146,10 @@ main() {
|
||||
printf "${RED}Change of default login shell has been cancelled!${NORMAL}\n"
|
||||
printf "${BLUE}To try again, run the following command at any time:\n${NORMAL}"
|
||||
printf ' %schsh -s "%s"%s\n' "${BLUE}" "$CHSH_ZSH" "${NORMAL}"
|
||||
# Probably best to fall back to the environment zsh if it exists.
|
||||
if [ -n "$ENV_ZSH" ]; then
|
||||
unset CHSH_ZSH
|
||||
fi
|
||||
break
|
||||
;;
|
||||
# Some other error code.
|
||||
@ -155,11 +157,15 @@ main() {
|
||||
case "$CHSH_ZSH_STDERR" in
|
||||
# The user entered a wrong password.
|
||||
*Credentials*)
|
||||
printf "${RED}Wrong password.${NORMAL} ${GREEN}Press CTRL-C to cancel.${NORMAL}\n"
|
||||
printf "${RED}Wrong password!${NORMAL} ${GREEN}Press CTRL-C to cancel.${NORMAL}\n"
|
||||
;;
|
||||
# The user entered an empty password.
|
||||
*Empty*)
|
||||
printf "${RED}Empty password!${NORMAL} ${GREEN}Press CTRL-C to cancel.${NORMAL}\n"
|
||||
;;
|
||||
# Unhandled error.
|
||||
*)
|
||||
printf "${RED}There was a problem changing the default login shell!${NORMAL}\n"
|
||||
printf "${RED}There was a problem changing the default login shell! See below.${NORMAL}\n"
|
||||
printf "${RED}${CHSH_ZSH_STDERR}${NORMAL}\n"
|
||||
# Probably best to fall back to the environment zsh if it exists.
|
||||
if [ -n "$ENV_ZSH" ]; then
|
||||
@ -177,12 +183,11 @@ main() {
|
||||
# Else, suggest the user change the login shell manually.
|
||||
else
|
||||
printf "I can't change your shell automatically because this system does not have chsh.\n"
|
||||
printf "${BLUE}Please manually change your default shell to ${CHSH_ZSH}!${NORMAL}\n"
|
||||
fi
|
||||
printf "${BLUE}Please manually change your default login shell to ${CHSH_ZSH}!${NORMAL}\n"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
printf "${BLUE}No TTY specified! Please manually change your default shell to zsh!${NORMAL}\n"
|
||||
printf "${BLUE}No input TTY! You will have to manually change your default login shell to zsh.${NORMAL}\n"
|
||||
fi
|
||||
|
||||
printf "${GREEN}"
|
||||
@ -202,9 +207,14 @@ main() {
|
||||
echo ''
|
||||
printf "${NORMAL}"
|
||||
|
||||
if [ -n "$CHSH_ZSH" ]; then
|
||||
exec "$CHSH_ZSH" -l
|
||||
elif [ -n "$ENV_ZSH" ]; then
|
||||
if ! [ -t 0 ] || [ -p /dev/stdin ]; then
|
||||
# Zsh exits immeditaly after invocation if STDIN is not a TTY, so it would be
|
||||
# pointless to exec it in the first place. Let's just print a message instead.
|
||||
printf "${BLUE}No input TTY! To begin using Oh My Zsh, start a new zsh session!${NORMAL}\n"
|
||||
exit 0
|
||||
elif [ -n "$CHSH_ZSH" ]; then
|
||||
exec "$CHSH_ZSH" --LOGIN
|
||||
else
|
||||
exec "$ENV_ZSH"
|
||||
fi
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user