Skip to content

Instantly share code, notes, and snippets.

@itchyny
Created February 26, 2023 13:47
Show Gist options
  • Save itchyny/7ef804d1662c78033cb17c1a478bc840 to your computer and use it in GitHub Desktop.
Save itchyny/7ef804d1662c78033cb17c1a478bc840 to your computer and use it in GitHub Desktop.
Change the login shell to zsh installed by Homebrew
#!/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