-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_mac.sh
More file actions
executable file
·138 lines (119 loc) · 3.75 KB
/
install_mac.sh
File metadata and controls
executable file
·138 lines (119 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/zsh
# macOS dotfiles installation script
# Needs to be zsh as we use zsh specific stuff
# Exit on error, undefined variables, and pipe failures
set -e
set -u
set -o pipefail
# Trap errors and show line number
trap 'echo "Error on line $LINENO. Exit code: $?"' ERR
# Version configuration
NVM_VERSION="v0.40.3"
if [[ "$TERM_PROGRAM" != "Apple_Terminal" ]]; then
echo "Please use the default apple terminal, we restart other programs during install and this may interrupt the install."
exit 0
fi
# Function to check if running with proper permissions
check_sudo() {
echo "Checking sudo access..."
sudo -v
}
# Function to install Homebrew if not present
install_homebrew() {
if command -v brew >/dev/null 2>&1; then
echo "Homebrew is already installed, updating..."
brew update
else
echo "Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
eval "$(/opt/homebrew/bin/brew shellenv)"
}
# Function to install Xcode command line tools
install_xcode_tools() {
echo "Installing Xcode command line tools..."
if ! xcode-select -p >/dev/null 2>&1; then
xcode-select --install
else
echo "Xcode command line tools already installed."
fi
}
# Function to install and setup Node.js via NVM
install_node() {
echo "Installing NVM and Node.js..."
if [ ! -d "$HOME/.nvm" ]; then
curl -o- "https://raw.githubusercontent.com/nvm-sh/nvm/${NVM_VERSION}/install.sh" | bash
else
echo "NVM already installed, updating..."
cd "$HOME/.nvm" && git fetch --tags origin && git checkout $(git describe --abbrev=0 --tags --match "v[0-9]*" $(git rev-list --tags --max-count=1))
cd -
fi
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
# Install latest LTS node
nvm install --lts
nvm use --lts
}
# Function to install CLI packages via Homebrew
install_cli_packages() {
echo "Installing CLI packages via Homebrew..."
brew install fzf \
gh \
git \
node \
python3 \
rustup \
shellcheck \
shfmt \
starship \
uv \
zsh-autosuggestions \
zsh-history-substring-search
}
# Function to install GUI applications via Homebrew Cask
install_applications() {
echo "Installing applications via Homebrew Cask..."
brew install --cask 1password \
arc \
discord \
font-fira-code-nerd-font \
google-chrome \
google-drive \
visual-studio-code
}
# Function to setup fzf integration
setup_fzf() {
echo "Setting up fzf integration..."
$(brew --prefix)/opt/fzf/install --key-bindings --completion --no-update-rc --no-bash
}
# Function to setup dotfiles project dependencies
setup_dotfiles() {
echo "Setting up dotfiles project..."
# Run Python configuration
echo "Running dotfiles configuration..."
uv run src/main.py
}
# Function to apply macOS system defaults
apply_system_defaults() {
echo "Applying macOS system defaults..."
source "$PWD/config/osx/.defaults"
}
# Main installation function
main_install() {
check_sudo
install_homebrew
install_xcode_tools
install_node
install_cli_packages
install_applications
setup_fzf
setup_dotfiles
apply_system_defaults
echo 'Please restart your terminal.'
}
# Only run main_install if this script is executed directly (not sourced)
# Works in both bash (BASH_SOURCE) and zsh (zsh_eval_context)
if [[ -z "${ZSH_EVAL_CONTEXT}" && "${BASH_SOURCE[0]}" == "${0}" ]] || \
[[ -n "${ZSH_EVAL_CONTEXT}" && "${ZSH_EVAL_CONTEXT}" != *:file ]]; then
main_install
fi