-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrapper.sh
More file actions
75 lines (63 loc) · 1.8 KB
/
wrapper.sh
File metadata and controls
75 lines (63 loc) · 1.8 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
#!/bin/bash
# Smart wrapper: prefer cache, fall back to USB
# Ensure paths.env exists (BusyBox-safe guard)
if [ ! -r /boot/config/nvim/paths.env ]; then
echo "[nvim-wrapper] ERROR: /boot/config/nvim/paths.env missing or unreadable."
exit 1
fi
# shellcheck disable=SC1091
. /boot/config/nvim/paths.env
# --- Verbosity system (future-proof) ---
# 0 = silent, 1 = basic, 2 = more, 3 = full debug
VERBOSE_LEVEL=0
# Parse -v / -vv / -vvv
for arg in "$@"; do
case "$arg" in
-v) VERBOSE_LEVEL=1 ;;
-vv) VERBOSE_LEVEL=2 ;;
-vvv) VERBOSE_LEVEL=3 ;;
esac
done
log() {
if [ "$VERBOSE_LEVEL" -ge "$1" ] && [ -t 1 ]; then
# Only print if running in an interactive terminal
shift
echo "[nvim-wrapper] $*"
fi
}
CACHE_MOUNTED=false
if grep -q " /mnt/cache " /proc/mounts 2>/dev/null; then
CACHE_MOUNTED=true
fi
CACHE_APP="$CACHE_ROOT/bin/nvim.appimage"
USB_APP="$USB_ROOT/bin/nvim.appimage"
# --- Auto-recovery: if cache exists but is missing the AppImage, repair it ---
if $CACHE_MOUNTED && [ ! -f "$CACHE_APP" ] && [ -f "$USB_APP" ]; then
log 1 "Cache missing nvim.appimage; restoring from USB..."
mkdir -p "$CACHE_ROOT/bin"
cp "$USB_APP" "$CACHE_APP" 2>/dev/null
chmod 755 "$CACHE_APP"
fi
# --- Select root (prefer cache if mounted and has an AppImage) ---
if $CACHE_MOUNTED && [ -f "$CACHE_APP" ]; then
ROOT="$CACHE_ROOT"
APP="$CACHE_APP"
SOURCE="CACHE"
elif [ -f "$USB_APP" ]; then
ROOT="$USB_ROOT"
APP="$USB_APP"
SOURCE="USB"
else
echo "ERROR: nvim.appimage not found in cache or USB."
exit 1
fi
# Export XDG dirs for the selected root
export XDG_CONFIG_HOME="$ROOT/config"
export XDG_DATA_HOME="$ROOT/data"
export XDG_STATE_HOME="$ROOT/state"
export XDG_CACHE_HOME="$ROOT/cache"
# --- Debug output based on verbosity ---
log 1 " Source: $SOURCE"
log 2 " Using ROOT: $ROOT"
log 3 " AppImage: $APP"
exec "$APP" "$@"