-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.zsh
More file actions
executable file
·227 lines (197 loc) · 5.53 KB
/
install.zsh
File metadata and controls
executable file
·227 lines (197 loc) · 5.53 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#!/usr/bin/env zsh
set -e
readonly HOMEBREW_INSTALL_URL=\
"https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh"
readonly ZSHLILLY_REPO_URL="https://github.com/MarkNenadov/zshlilly.git"
readonly MISE_JAVA_VERSION="zulu-24.32.13.0"
source "$(pwd)/zsh/lib/logging.zsh"
source "$(pwd)/zsh/lib/inject-aliases.zsh"
# Backup existing file and create symlink
backup_and_link() {
local source_file="$1"
local target_path="$2"
local is_directory="${3:-false}"
if [[ -e "$target_path" && ! -L "$target_path" ]]; then
mv "$target_path" "${target_path}OLD"
fi
if [[ "$is_directory" == "true" ]]; then
ln -sfn "$source_file" "$target_path"
else
ln -sf "$source_file" "$target_path"
fi
}
DRY_RUN=false
QUIET=false
INJECT_ALIASES=""
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
--dry-run)
DRY_RUN=true
shift
;;
--skip-brew)
SKIP_BREW=true
shift
;;
--quiet)
QUIET=true
shift
;;
--inject-aliases)
INJECT_ALIASES="$2"
if [[ -z "$INJECT_ALIASES" ]]; then
echo "Error: --inject-aliases requires a target file path"
exit 1
fi
shift 2
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done
handle_inject_aliases() {
if [[ -n "$INJECT_ALIASES" ]]; then
inject_aliases "$INJECT_ALIASES" "$DRY_RUN"
return $?
fi
}
handle_inject_aliases
if [[ -n "$INJECT_ALIASES" ]]; then
exit 0
fi
do_brew() {
if [[ "$SKIP_BREW" != "true" ]]; then
if [[ ! $(which brew) ]]; then
if [[ ! -x "/usr/bin/ruby" ]]; then
echo "Error: /usr/bin/ruby not found. Cannot install Homebrew."
echo "Try running with --skip-brew to skip Homebrew installation."
exit 1
fi
if [[ "$DRY_RUN" == "true" ]]; then
log_dry_run "Would install Homebrew..."
else
log "Installing homebrew..."
/usr/bin/ruby -e "$(curl -fsSL $HOMEBREW_INSTALL_URL)"
echo 'eval "$(brew shellenv)"' >> $HOME/.zprofile
eval "$(brew shellenv)"
fi
fi
if [[ "$DRY_RUN" == "true" ]]; then
log_dry_run "Would install Homebrew dependencies..."
else
log "Installing dependencies via Homebrew..."
brew tap anchore/grype
if [[ "$QUIET" == "true" ]]; then
HOMEBREW_NO_AUTO_UPDATE=1 brew bundle --quiet 2>/dev/null
brew_result=$?
else
HOMEBREW_NO_AUTO_UPDATE=1 brew bundle
brew_result=$?
fi
# Check for specific known issues and continue
if [[ $brew_result -eq 0 ]]; then
log "All dependencies installed"
else
log "Warning: Some Homebrew dependencies failed to install"
log "This is usually due to version conflicts with existing apps"
log "Continuing with installation..."
fi
fi
fi
}
do_brew
if [[ "$DRY_RUN" == "true" ]]; then
log_dry_run \
"Would be installing vs code extensions from vscode/extensions.txt"
else
log "Installing vs code extensions from vscode/extensions.txt"
cat vscode/extensions.txt | \
xargs -n 1 code --install-extension >/dev/null 2>&1
fi
if [[ "$DRY_RUN" == "true" ]]; then
log_dry_run \
"Would be installing cursor extensions from cursor/extensions.txt"
else
log "Installing cursor extensions from cursor/extensions.txt"
cat cursor/extensions.txt | \
xargs -n 1 cursor --install-extension >/dev/null 2>&1
fi
log "Linking dotfiles..."
link_dotfiles() {
if [[ "$DRY_RUN" == "true" ]]; then
log_dry_run "Would link:"
echo " - gitconfig -> $HOME/.gitconfig"
echo " - zshrc -> $HOME/.zshrc"
echo " - zsh/ -> $HOME/.zsh"
echo " - vimrc -> $HOME/.vimrc"
echo " - vscode/settings.json -> " \
"$HOME/Library/Application Support/Code/User/settings.json"
echo " - cursor/settings.json -> " \
"$HOME/Library/Application Support/Cursor/User/settings.json"
else
# Handle gitconfig
backup_and_link "$(pwd)/gitconfig" "$HOME/.gitconfig"
# Handle zshrc
backup_and_link "$(pwd)/zshrc" "$HOME/.zshrc"
# Handle zsh directory
backup_and_link "$(pwd)/zsh" "$HOME/.zsh" true
# Handle claude directory
backup_and_link "$(pwd)/claude" "$HOME/.claude" true
# Handle vimrc
backup_and_link "$(pwd)/vimrc" "$HOME/.vimrc"
# Handle VS Code settings
mkdir -p "$HOME/Library/Application Support/Code/User"
backup_and_link "$(pwd)/vscode/settings.json" \
"$HOME/Library/Application Support/Code/User/settings.json"
# Handle Cursor settings
mkdir -p "$HOME/Library/Application Support/Cursor/User"
backup_and_link "$(pwd)/cursor/settings.json" \
"$HOME/Library/Application Support/Cursor/User/settings.json"
fi
}
link_dotfiles
log "Installing zshlilly in $HOME"
install_zshlilly() {
if [[ "$DRY_RUN" == "true" ]]; then
log_dry_run "Would install zshlilly"
else
git clone $ZSHLILLY_REPO_URL
cd zshlilly
./install.zsh $HOME
cd ..
rm -rf zshlilly
fi
}
install_zshlilly
install_language_runtimes() {
if [[ "$DRY_RUN" == "true" ]]; then
log_dry_run "Would be installing python, ruby, and java with mise"
else
log "Installing python, ruby, and java with mise"
mise install python@latest
mise install ruby@latest
mise install java@$MISE_JAVA_VERSION
mise use -g python@latest ruby@latest java@$MISE_JAVA_VERSION
fi
}
install_language_runtimes
install_python_dependencies() {
if [[ "$DRY_RUN" == "true" ]]; then
log_dry_run \
"Would install Python dependencies from python/python-requirements.txt"
else
log \
"Installing python dependencies from python/python-requirements.txt"
pip install --upgrade pip
python3 -m pip install -r python/python-requirements.txt
fi
}
install_python_dependencies
if [[ "$DRY_RUN" == "true" ]]; then
log_dry_run "Installation simulation complete. No changes were made."
else
log "Finished."
fi