-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathi
More file actions
540 lines (474 loc) · 14.3 KB
/
Copy pathi
File metadata and controls
540 lines (474 loc) · 14.3 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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
#!/bin/bash
# VimZap Installer - https://github.com/IFAKA/vimzap
# Verify: curl -fsSL ifaka.github.io/vimzap/i | less
set -euo pipefail
VIMZAP_MARKER="# VimZap aliases"
BASE_URL="https://raw.githubusercontent.com/IFAKA/vimzap/main"
# Single source of truth for config files
CONFIG_FILES=(
"init.lua"
"lua/options.lua"
"lua/plugins.lua"
"lua/lsp.lua"
"lua/debug.lua"
"lua/keymaps.lua"
"lua/benchmark.lua"
"lua/md-share.lua"
"lua/health.lua"
"ftdetect/isml.vim"
"ftdetect/ds.vim"
"syntax/isml.vim"
"syntax/ds.vim"
"scripts/md-server.py"
)
# Single source of truth for VimZap plugins
VIMZAP_PLUGINS=(
"williamboman/mason.nvim"
"folke/snacks.nvim"
"folke/which-key.nvim"
"hrsh7th/nvim-cmp"
"hrsh7th/cmp-nvim-lsp"
"hrsh7th/cmp-buffer"
"hrsh7th/cmp-path"
"lewis6991/gitsigns.nvim"
"MeanderingProgrammer/render-markdown.nvim"
"stevearc/conform.nvim"
"echasnovski/mini.nvim"
"nvim-treesitter/nvim-treesitter"
"mfussenegger/nvim-dap"
"rcarriga/nvim-dap-ui"
"nvim-neotest/nvim-nio"
"IFAKA/prophet.nvim"
)
get_shell_rc() {
if [[ -n "${ZSH_VERSION:-}" ]] || [[ "$SHELL" == *"zsh"* ]]; then
echo "$HOME/.zshrc"
elif [[ -n "${BASH_VERSION:-}" ]] || [[ "$SHELL" == *"bash"* ]]; then
if [[ "$(uname -s)" == "Darwin" ]]; then
echo "$HOME/.bash_profile"
else
echo "$HOME/.bashrc"
fi
else
echo "$HOME/.profile"
fi
}
add_aliases() {
local rc_file
rc_file=$(get_shell_rc)
# Replace older VimZap alias blocks so updates get the latest shell helpers.
remove_aliases >/dev/null 2>&1 || true
echo "" >> "$rc_file"
echo "$VIMZAP_MARKER" >> "$rc_file"
cat >> "$rc_file" <<'EOF'
v() {
if [ "$#" -eq 1 ]; then
_vimzap_target="${1%:*}"
_vimzap_line="${1##*:}"
if [ "$_vimzap_target" != "$1" ] && [ -n "$_vimzap_target" ] && [ -e "$_vimzap_target" ]; then
case "$_vimzap_line" in
""|*[!0-9]*) ;;
*) nvim "+$_vimzap_line" "$_vimzap_target"; return ;;
esac
fi
fi
nvim "$@"
}
alias vi='nvim'
alias vim='nvim'
EOF
echo "$VIMZAP_MARKER end" >> "$rc_file"
}
remove_aliases() {
local rc_file
rc_file=$(get_shell_rc)
if [[ -f "$rc_file" ]] && grep -q "$VIMZAP_MARKER" "$rc_file"; then
# Remove lines between markers (inclusive)
sed -i.bak "/$VIMZAP_MARKER/,/$VIMZAP_MARKER end/d" "$rc_file"
rm -f "${rc_file}.bak"
echo " Removed aliases from $rc_file"
fi
}
uninstall() {
echo ""
echo " VimZap Uninstall"
echo " ================"
echo ""
echo " This will remove:"
echo " - ~/.config/nvim (VimZap config)"
echo " - ~/.local/share/nvim (plugins & data)"
echo " - ~/.cache/nvim (cache files)"
echo " - Shell aliases (v, vi, vim)"
echo ""
if [[ "$SKIP_PROMPTS" != "true" ]]; then
read -p " Are you sure? (y/N) " -n 1 -r
echo ""
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo " Uninstall cancelled."
exit 0
fi
echo ""
fi
# Remove aliases
remove_aliases
# Kill any running md-share servers
if lsof -ti:8765 >/dev/null 2>&1; then
echo " Stopping markdown share server..."
kill $(lsof -ti:8765) 2>/dev/null || true
fi
# Create backup before removing (just in case)
if [[ -d ~/.config/nvim ]]; then
echo " Creating backup at ~/.config/nvim.backup.$(date +%s)..."
cp -r ~/.config/nvim ~/.config/nvim.backup.$(date +%s)
fi
# Remove nvim config and data
echo " Removing config..."
rm -rf ~/.config/nvim
echo " Removing plugins and data..."
rm -rf ~/.local/share/nvim
echo " Removing cache..."
rm -rf ~/.cache/nvim
echo ""
echo " ✓ VimZap uninstalled successfully!"
echo " Backup saved at ~/.config/nvim.backup.*"
echo ""
echo " Run: source $(get_shell_rc)"
echo ""
}
# Parse flags
SKIP_PROMPTS=false
ACTION=""
for arg in "$@"; do
case "$arg" in
--uninstall|uninstall)
ACTION="uninstall"
;;
--update|update)
ACTION="update"
;;
--yes|-y)
SKIP_PROMPTS=true
;;
esac
done
# Check for --uninstall flag
if [[ "$ACTION" == "uninstall" ]]; then
uninstall
exit 0
fi
update() {
echo ""
echo " VimZap Update"
echo " ============="
echo ""
# Counters for summary
local config_updated=0
local config_unchanged=0
local plugins_updated=0
local plugins_unchanged=0
local plugins_failed=0
# Update config files
echo " Updating config..."
mkdir -p ~/.config/nvim/lua
mkdir -p ~/.config/nvim/ftdetect
mkdir -p ~/.config/nvim/syntax
mkdir -p ~/.config/nvim/scripts
for file in "${CONFIG_FILES[@]}"; do
local dest="$HOME/.config/nvim/$file"
local temp="/tmp/vimzap_${file//\//_}"
# Download to temp file
if curl -fsSL "$BASE_URL/$file" -o "$temp" 2>/dev/null; then
# Check if file exists and has changed
if [[ -f "$dest" ]]; then
if ! cmp -s "$dest" "$temp"; then
mv "$temp" "$dest"
echo " Updated: $file"
((config_updated++))
else
rm "$temp"
((config_unchanged++))
fi
else
mv "$temp" "$dest"
echo " Added: $file"
((config_updated++))
fi
else
echo " Failed: $file"
rm -f "$temp"
fi
done
if [[ $config_unchanged -gt 0 ]]; then
echo " ($config_unchanged unchanged)"
fi
# Make scripts executable
chmod +x ~/.config/nvim/scripts/md-server.py
# Update plugins
echo ""
echo " Updating plugins..."
PLUGIN_DIR="$HOME/.local/share/nvim/site/pack/plugins/opt"
local plugins_installed=0
# First, install any missing plugins
mkdir -p "$PLUGIN_DIR"
for plugin in "${VIMZAP_PLUGINS[@]}"; do
name=$(basename "$plugin")
if [[ ! -d "$PLUGIN_DIR/$name" ]]; then
printf " %s... " "$name"
if git clone --depth=1 --quiet "https://github.com/$plugin" "$PLUGIN_DIR/$name" 2>/dev/null; then
echo "installed"
((plugins_installed++))
else
echo "failed to install"
((plugins_failed++))
fi
fi
done
# Then, update existing plugins
if [[ ! -d "$PLUGIN_DIR" ]]; then
echo " No plugins directory found"
else
for dir in "$PLUGIN_DIR"/*/; do
if [[ ! -d "$dir" ]]; then
continue
fi
name=$(basename "$dir")
# Skip if we just installed this plugin
local just_installed=false
for plugin in "${VIMZAP_PLUGINS[@]}"; do
if [[ "$(basename "$plugin")" == "$name" ]] && [[ ! -d "$dir/.git" ]] || [[ $plugins_installed -gt 0 ]]; then
just_installed=true
break
fi
done
# Skip newly installed plugins in the update loop
if [[ $just_installed == true ]] && [[ ! -d "$dir/.git" ]]; then
continue
fi
printf " %s... " "$name"
# Check if it's a git repo
if [[ ! -d "$dir/.git" ]]; then
echo "not a git repo"
((plugins_failed++))
continue
fi
# Get current HEAD before pulling
local old_head=$(git -C "$dir" rev-parse HEAD 2>/dev/null)
# Pull changes
if git -C "$dir" pull --quiet 2>/dev/null; then
local new_head=$(git -C "$dir" rev-parse HEAD 2>/dev/null)
if [[ "$old_head" != "$new_head" ]]; then
# Get number of new commits
local commit_count=$(git -C "$dir" rev-list --count "$old_head..$new_head" 2>/dev/null || echo "?")
echo "updated (+$commit_count commits)"
((plugins_updated++))
else
echo "up to date"
((plugins_unchanged++))
fi
else
echo "failed"
((plugins_failed++))
fi
done
fi
# Update shell aliases/functions
echo ""
echo " Updating aliases..."
add_aliases
echo " Updated: $(get_shell_rc)"
# Summary
echo ""
echo " Summary"
echo " -------"
echo " Config files: $config_updated updated, $config_unchanged unchanged"
if [[ $plugins_installed -gt 0 ]]; then
echo " Plugins: $plugins_installed installed, $plugins_updated updated, $plugins_unchanged up to date"
else
echo " Plugins: $plugins_updated updated, $plugins_unchanged up to date"
fi
if [[ $plugins_failed -gt 0 ]]; then
echo " Failed: $plugins_failed plugins"
fi
echo ""
# Suggest health check if updates were made
if [[ $config_updated -gt 0 || $plugins_updated -gt 0 || $plugins_installed -gt 0 ]]; then
echo " ✓ Updates applied successfully!"
echo ""
echo " Verify everything works:"
echo " nvim -c 'VimZapHealth'"
echo ""
else
echo " ✓ Already up to date!"
echo ""
fi
}
# Check for --update flag
if [[ "$ACTION" == "update" ]]; then
update
exit 0
fi
main() {
echo ""
echo " VimZap Installer"
echo " ================"
echo ""
OS="$(uname -s)"
if [[ "$OS" != "Darwin" && "$OS" != "Linux" ]]; then
echo "Error: Unsupported OS: $OS (only macOS and Linux supported)"
exit 1
fi
echo " OS: $OS"
echo ""
# Check for existing nvim config and warn
if [[ -d "$HOME/.config/nvim" ]]; then
echo " Warning: Existing Neovim config detected!"
echo " This will overwrite: ~/.config/nvim"
echo ""
if [[ "$SKIP_PROMPTS" != "true" ]]; then
read -p " Continue? (y/N) " -n 1 -r
echo ""
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo " Installation cancelled."
exit 0
fi
echo ""
else
echo " Continuing (--yes flag provided)..."
echo ""
fi
fi
# macOS
if [[ "$OS" == "Darwin" ]]; then
echo " [1/6] Installing tools via Homebrew..."
if ! command -v brew &>/dev/null; then
echo " Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
brew install neovim git node tree-sitter-cli ripgrep fzf lazygit 2>/dev/null || {
echo " Some packages may have failed, continuing..."
}
fi
# Linux
if [[ "$OS" == "Linux" ]]; then
echo " [1/6] Installing tools..."
if command -v apt-get &>/dev/null; then
sudo apt-get update -qq
sudo apt-get install -y neovim git nodejs npm ripgrep fzf curl
# lazygit via binary
if ! command -v lazygit &>/dev/null; then
echo " Installing lazygit..."
LAZYGIT_VERSION=$(curl -s "https://api.github.com/repos/jesseduffield/lazygit/releases/latest" | sed -n 's/.*"tag_name": "v\([^"]*\)".*/\1/p' | head -1)
curl -Lo /tmp/lazygit.tar.gz "https://github.com/jesseduffield/lazygit/releases/latest/download/lazygit_${LAZYGIT_VERSION}_Linux_x86_64.tar.gz"
sudo tar xf /tmp/lazygit.tar.gz -C /usr/local/bin lazygit
rm /tmp/lazygit.tar.gz
fi
elif command -v dnf &>/dev/null; then
sudo dnf install -y neovim git nodejs npm ripgrep fzf
sudo dnf copr enable atim/lazygit -y 2>/dev/null && sudo dnf install -y lazygit || true
elif command -v pacman &>/dev/null; then
sudo pacman -Sy --noconfirm neovim git nodejs npm ripgrep fzf lazygit
else
echo " Warning: Unknown package manager."
echo " Please install manually: neovim git nodejs npm tree-sitter-cli ripgrep fzf lazygit"
fi
if ! command -v tree-sitter &>/dev/null; then
echo " Installing tree-sitter CLI..."
if command -v npm &>/dev/null; then
sudo npm install -g tree-sitter-cli 2>/dev/null || {
echo " Failed to install tree-sitter CLI via npm."
echo " Install manually: npm install -g tree-sitter-cli"
}
else
echo " npm not found. Install manually: npm install -g tree-sitter-cli"
fi
fi
fi
# Check Neovim version
echo " [2/6] Checking Neovim version..."
if command -v nvim &>/dev/null; then
NVIM_VERSION=$(nvim --version 2>/dev/null | head -1 | sed -n 's/.*v\([0-9]*\.[0-9]*\).*/\1/p')
if [[ -z "$NVIM_VERSION" ]]; then
NVIM_VERSION="0.0"
fi
NVIM_MAJOR=$(echo "$NVIM_VERSION" | cut -d. -f1)
NVIM_MINOR=$(echo "$NVIM_VERSION" | cut -d. -f2)
echo " Found: v${NVIM_VERSION}"
if [[ "$NVIM_MAJOR" -eq 0 && "$NVIM_MINOR" -lt 11 ]]; then
echo ""
echo " Error: VimZap requires Neovim 0.11 or higher"
echo " Your version: v${NVIM_VERSION}"
echo ""
echo " Update Neovim:"
if [[ "$OS" == "Darwin" ]]; then
echo " brew upgrade neovim"
else
echo " See: https://github.com/neovim/neovim/releases"
fi
exit 1
fi
else
echo " Neovim not found (will be installed)"
fi
echo ""
# Directories
echo " [3/6] Setting up config..."
mkdir -p ~/.config/nvim/lua
mkdir -p ~/.config/nvim/ftdetect
mkdir -p ~/.config/nvim/syntax
mkdir -p ~/.config/nvim/scripts
mkdir -p ~/.local/share/nvim/site/pack/plugins/opt
# Download config files
for file in "${CONFIG_FILES[@]}"; do
if ! curl -fsSL "$BASE_URL/$file" -o ~/.config/nvim/"$file"; then
echo "Error: Failed to download $file"
exit 1
fi
done
# Make scripts executable
chmod +x ~/.config/nvim/scripts/md-server.py
# Plugins
echo " [4/6] Installing plugins..."
PLUGIN_DIR="$HOME/.local/share/nvim/site/pack/plugins/opt"
for plugin in "${VIMZAP_PLUGINS[@]}"; do
name=$(basename "$plugin")
if [[ ! -d "$PLUGIN_DIR/$name" ]]; then
printf " %s " "$name"
if git clone --depth=1 --quiet "https://github.com/$plugin" "$PLUGIN_DIR/$name" 2>/dev/null; then
echo "ok"
else
echo "failed"
fi
fi
done
# LSP servers (installed via Mason on first launch)
echo " [5/6] LSP servers will be installed via Mason on first launch..."
# Add shell aliases
echo " [6/6] Setting up aliases..."
add_aliases
echo " v -> nvim (supports path:line), vi/vim -> nvim"
echo ""
echo " Done! Run: source $(get_shell_rc)"
echo ""
echo " Usage:"
echo " v Open Neovim (also vi, vim)"
echo " v file:line Open file at line"
echo " <Space> Show all commands"
echo " <Space>e File explorer"
echo " <Space>ff Find files"
echo " <Space>fg Grep"
echo ""
echo " Explorer keys:"
echo " a Add file/folder"
echo " d Delete"
echo " r Rename"
echo " m Move"
echo " c Copy"
echo ""
echo " Update:"
echo " bash <(curl -fsSL ifaka.github.io/vimzap/i) update"
echo ""
echo " Uninstall:"
echo " bash <(curl -fsSL ifaka.github.io/vimzap/i) uninstall"
echo ""
}
main "$@"