Created
February 26, 2023 13:47
-
-
Save itchyny/7ef804d1662c78033cb17c1a478bc840 to your computer and use it in GitHub Desktop.
Change the login shell to zsh installed by Homebrew
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -euo pipefail | |
echo "Checking zsh installed by Homebrew ..." | |
if version="$(brew list --versions zsh)"; then | |
echo "Found: $version" | |
else | |
echo "Could not find zsh installed by Homebrew" | |
exit 1 | |
fi | |
zsh_path="$(brew --prefix)/bin/zsh" | |
if [[ ! -x "$zsh_path" ]]; then | |
echo "Could not find zsh executable" | |
exit 1 | |
fi | |
echo "Checking the login shell ..." | |
user_shell="$(dscl . -read "$HOME" UserShell | awk '{print $2}')" | |
if [[ "$user_shell" == "$zsh_path" ]]; then | |
echo "The login shell is already $zsh_path" | |
else | |
echo "Changing the login shell from $user_shell to $zsh_path ..." | |
sudo dscl . -create "$HOME" UserShell "$zsh_path" | |
echo "Checking the login shell again ..." | |
dscl . -read "$HOME" UserShell | |
fi | |
echo "Done!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment