-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall_script.sh
More file actions
executable file
·323 lines (280 loc) · 10.1 KB
/
Copy pathinstall_script.sh
File metadata and controls
executable file
·323 lines (280 loc) · 10.1 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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
#!/bin/bash
# Exit on error (except during uninstall where we want to keep going if a file is already missing)
set -e
# -----------------------------------------------------------------------------
# Configuration & Paths
# -----------------------------------------------------------------------------
SRC_DIR="$HOME/.local/src"
BIN_DIR="$HOME/.local/bin"
# Detect System Architecture
ARCH=$(uname -m)
case "$ARCH" in
x86_64|amd64)
TMUX_ARCH="x86_64|amd64"
TS_ARCH="x64"
;;
aarch64|arm64)
TMUX_ARCH="aarch64|arm64"
TS_ARCH="arm64"
;;
*)
echo "Error: Unsupported architecture ($ARCH)"
exit 1
;;
esac
# Helper function to clone or pull a git repo incrementally
sync_repo() {
local url=$1
local dir=$2
if [ -d "$dir" ]; then
echo "Updating Git repository: $(basename "$dir")..."
cd "$dir"
git stash --quiet || true
git pull || {
echo "Pull failed. Resetting and cloning fresh..."
cd .. && rm -rf "$dir"
git clone --depth 1 "$url" "$dir" && cd "$dir"
}
else
echo "Cloning Git repository: $(basename "$dir")..."
git clone --depth 1 "$url" "$dir"
cd "$dir"
fi
}
# -----------------------------------------------------------------------------
# Installation / Update Actions
# -----------------------------------------------------------------------------
manage_rust() {
if ! command -v cargo &> /dev/null; then
echo "Installing Rust..."
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source "$HOME/.cargo/env"
else
echo "Updating Rust toolchain..."
rustup update
fi
}
manage_zvm_zig() {
if ! command -v zvm &> /dev/null; then
echo "Installing ZVM..."
curl https://www.zvm.app/install.sh | bash
export PATH="$HOME/.zvm/bin:$HOME/.zvm/self:$PATH"
else
echo "Updating ZVM..."
zvm upgrade
fi
echo "Ensuring Zig 0.15.2 is configured..."
zvm install 0.15.2
zvm use 0.15.2
}
manage_zmx() {
sync_repo "https://github.com/neurosnap/zmx.git" "$SRC_DIR/zmx"
echo "Building ZMX Multiplexer..."
zig build -Doptimize=ReleaseSafe --prefix "$HOME/.local"
}
manage_pixi() {
if ! command -v pixi &> /dev/null; then
echo "Installing Pixi..."
curl -fsSL https://pixi.sh/install.sh | bash
export PATH="$HOME/.pixi/bin:$PATH"
else
echo "Updating Pixi..."
pixi self-update
fi
}
manage_fish() {
sync_repo "https://github.com/fish-shell/fish-shell.git" "$SRC_DIR/fish-shell"
echo "Building/Updating Fish Shell from source..."
cmake . -DCMAKE_INSTALL_PREFIX="$HOME/.local/"
make && make install
}
manage_neovim() {
sync_repo "https://github.com/neovim/neovim.git" "$SRC_DIR/neovim"
echo "Building/Updating Neovim from source..."
make CMAKE_BUILD_TYPE=Release CMAKE_INSTALL_PREFIX="$HOME/.local"
make install
}
manage_cargo_tools() {
echo "Managing Cargo ecosystem tools..."
cargo install --force yazi-build
if ! command -v cargo-install-update &> /dev/null; then
echo "Installing cargo-update manager with vendored OpenSSL..."
cargo install cargo-update --features vendored-openssl
fi
declare -A tools=(
[rg]=ripgrep [bat]=bat [eza]=eza [fd]=fd-find [zoxide]=zoxide [sk]=skim [tuckr]=tuckr
)
for bin in "${!tools[@]}"; do
if ! command -v "$bin" &> /dev/null; then
echo "Installing missing tool: ${tools[$bin]}..."
cargo install "${tools[$bin]}"
fi
done
echo "Bumping out-of-date Cargo packages safely..."
cargo install-update ripgrep bat eza fd-find zoxide skim tuckr
cargo install cargo-update --features vendored-openssl
}
manage_treesitter() {
if ! command -v cargo &> /dev/null; then
echo "Error: Cargo does not exist."
return 1
fi
if ! command -v clang &> /dev/null; then
if command -v pixi &> /dev/null; then
pixi global install --environment llvm clang libclang
export PATH="$HOME/.pixi/bin:$PATH"
export LIBCLANG_PATH="$HOME/.pixi/envs/llvm/lib"
CC=clang CXX=clang++ cargo install tree-sitter-cli
else
echo "Error: Pixi does not exist."
return 1
fi
else
cargo install tree-sitter-cli
fi
}
manage_oh_my_posh() {
if ! command -v oh-my-posh &> /dev/null; then
curl -s https://ohmyposh.dev/install.sh | bash -s -- -d "$BIN_DIR"
else
oh-my-posh upgrade
fi
}
manage_ghostty() {
cd "$SRC_DIR"
curl -sLO https://raw.githubusercontent.com/ghostty-org/ghostty/main/terminfo/ghostty.terminfo
tic -x -o "$HOME/.terminfo" ghostty.terminfo
rm -f ghostty.terminfo
}
manage_tmux() {
echo "Checking GitHub for the latest Tmux release..."
DOWNLOAD_URL=$(curl -s https://api.github.com/repos/tmux/tmux-builds/releases/latest | grep '"browser_download_url":' | grep 'linux' | grep -E "$TMUX_ARCH" | head -n 1 | sed -E 's/.*"([^"]+)".*/\1/')
if [ -z "$DOWNLOAD_URL" ]; then echo "Warning: Skipping Tmux update."; return; fi
FILENAME=$(basename "$DOWNLOAD_URL")
CLEAN_VER=$(echo "$FILENAME" | sed -E 's/tmux-([^_-]+)-.*/\1/')
if ! command -v tmux &> /dev/null || [[ "$(tmux -V 2>/dev/null)" != *"$CLEAN_VER"* ]]; then
echo "Installing/Updating to static Tmux version $CLEAN_VER..."
cd "$SRC_DIR"
curl -sLO "$DOWNLOAD_URL"
tar -xzf "$FILENAME"
mv tmux "$BIN_DIR/tmux"
rm -f "$FILENAME"
fi
}
manage_direnv() {
curl -sfL https://direnv.net/install.sh | bin_path=$HOME/.local/bin bash
}
configure_env() {
if ! grep -q "# --- Custom Environment ---" "$HOME/.bashrc"; then
cat << 'EOF' >> "$HOME/.bashrc"
# --- Custom Environment ---
export PATH="$HOME/.local/bin:$HOME/.cargo/bin:$HOME/.zvm/bin:$HOME/.zvm/self:$HOME/.pixi/bin:$PATH"
# Launch fish automatically for SSH sessions
if [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then
# Check if fish is installed before trying to run it
if command -v fish >/dev/null 2>&1; then
exec fish
fi
fi
EOF
fi
}
# -----------------------------------------------------------------------------
# Uninstall Actions
# -----------------------------------------------------------------------------
execute_uninstall() {
echo "!!! WARNING: This will completely erase all tools, plugins, and caches managed by this script !!!"
read -p "Are you absolutely sure you want to proceed? (y/N): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Uninstall aborted."
exit 0
fi
# Allow errors to pass during uninstall so missing folders don't halt progress
set +e
# 1. Clear Yazi system /tmp cache using the CLI before deleting files
if command -v yazi &> /dev/null; then
echo "Asking Yazi to purge temporary system caches..."
yazi --clear-cache
fi
echo "Removing source code and temporary build workspaces..."
rm -rf "$SRC_DIR"
echo "Removing isolated package managers (Rust, Pixi, ZVM)..."
# Note: Removing .cargo automatically uninstalls our new tree-sitter-cli!
rm -rf "$HOME/.cargo" "$HOME/.rustup"
rm -rf "$HOME/.pixi"
rm -rf "$HOME/.zvm"
echo "Removing specific local binaries..."
# We still clean tree-sitter here just in case an old pre-built one is lingering
cd "$BIN_DIR" && rm -f fish nvim tmux tree-sitter oh-my-posh zmx rg bat eza fd zoxide sk tuckr yazi yazi-cli yazi-build cargo-install-update
echo "Removing Ghostty terminfo mappings..."
rm -f "$HOME/.terminfo/g/ghostty"
echo "--- DEEP CLEAN: Purging Application Plugins, States, & Caches ---"
# 2. CONFIGS PRESERVED: Left commented out because they are linked by tuckr
echo "Preserving configuration files in ~/.config/..."
# rm -rf "$HOME/.config/nvim"
# rm -rf "$HOME/.config/fish"
# rm -rf "$HOME/.config/yazi"
# 3. Clean up Neovim state and local plugin downloads
echo "Clearing Neovim leftovers..."
rm -rf "$HOME/.local/share/nvim"
rm -rf "$HOME/.local/state/nvim"
rm -rf "$HOME/.local/lib/nvim"
rm -rf "$HOME/.cache/nvim"
# 4. Clean up Fish Shell data history
echo "Clearing Fish Shell leftovers..."
rm -rf "$HOME/.local/share/fish"
# 5. Clean up Yazi data folders
echo "Clearing Yazi leftovers..."
rm -rf "$HOME/.local/share/yazi"
rm -rf "$HOME/.cache/yazi"
# 6. Clean up remaining background utility tracking
echo "Clearing remaining terminal utility leftovers (Zoxide, ZMX, Oh-My-Posh)..."
rm -rf "$HOME/.local/share/zoxide"
rm -rf "$HOME/.local/share/zmx"
rm -rf "$HOME/.local/state/zmx"
rm -rf "$HOME/.cache/pixi"
rm -rf "$HOME/.cache/zig"
rm -rf "$HOME/.cache/oh-my-posh"
rm -rf "$HOME/.local/bin/direnv"
echo "Cleaning up .bashrc shell paths and auto-starts..."
if [ -f "$HOME/.bashrc" ]; then
# Delete from the custom environment marker all the way to the end of the file
sed -i '/# --- Custom Environment ---/,$d' "$HOME/.bashrc"
fi
echo "--- Uninstall Complete ---"
echo "Your machine is clean. Configuration files were preserved for tuckr."
echo "Please run 'source ~/.bashrc' or restart your terminal to finish."
}
# -----------------------------------------------------------------------------
# Runtime Controller
# -----------------------------------------------------------------------------
MODE=${1:-install}
case "$MODE" in
install|update)
mkdir -p "$SRC_DIR" "$BIN_DIR" "$HOME/.terminfo"
echo "--- Initializing No-Root Environment Setup [Mode: ${MODE^^}] ---"
manage_rust
manage_zvm_zig
manage_zmx
manage_pixi
manage_fish
manage_neovim
manage_cargo_tools
manage_treesitter
manage_oh_my_posh
manage_ghostty
manage_tmux
manage_direnv
configure_env
echo "--- Setup/Update Action Complete! ---"
;;
uninstall)
execute_uninstall
;;
*)
echo "Error: Invalid argument."
echo "Usage: $0 [install|update|uninstall]"
exit 1
;;
esac