1#!/usr/bin/env bash
2set -euo pipefail
3ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
4source "$ROOT/lib.sh"
5
6need_cmd brew
7
8#──────────────────────────────────────────────────────────────
9# STATE: Preferred login shell (edit this value)
10#──────────────────────────────────────────────────────────────
11LOGIN_SHELL="bash" # Options: bash, zsh
12
13#──────────────────────────────────────────────────────────────
14# LOGIC: Idempotent shell configuration
15#──────────────────────────────────────────────────────────────
16
17# Resolve shell path
18case "$LOGIN_SHELL" in
19 bash)
20 shell_path="$(brew --prefix)/bin/bash"
21 ;;
22 zsh)
23 shell_path="$(brew --prefix)/bin/zsh"
24 ;;
25 *)
26 warn "Unknown shell: $LOGIN_SHELL"
27 exit 1
28 ;;
29esac
30
31log "Ensuring login shell is $shell_path"
32
33# Check if shell is in /etc/shells
34if ! grep -qxF "$shell_path" /etc/shells; then
35 log "Adding $shell_path to /etc/shells"
36 echo "$shell_path" | sudo tee -a /etc/shells >/dev/null
37fi
38
39# Change shell if different
40if [[ "$SHELL" != "$shell_path" ]]; then
41 log "Changing login shell to $shell_path"
42 chsh -s "$shell_path"
43else
44 log "Login shell already set to $shell_path"
45fi
46
47log "Login shell configured"