-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup
More file actions
executable file
·76 lines (68 loc) · 2.83 KB
/
Copy pathsetup
File metadata and controls
executable file
·76 lines (68 loc) · 2.83 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
#!/usr/bin/env bash
# mathpaste setup — installs the converter runtime and a Hammerspoon hotkey
# (⌘⇧V) that converts LaTeX on the clipboard into native Word equations.
#
# Cmd+C is never intercepted: mathpaste only runs when you press the hotkey.
#
# ./setup install + wire the hotkey
# ./setup --uninstall remove everything
set -euo pipefail
REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
LABEL="com.eliasmocik.mathpaste"
# The repo IS the runtime — the hotkey points straight at $REPO/mathpaste.py, so
# there's a single source of truth (editing the script takes effect immediately,
# no copy step). If the repo lives under ~/Desktop, grant Hammerspoon Full Disk
# Access so it can read it. $OLD_INSTALL is a legacy runtime copy we clean up.
OLD_INSTALL="$HOME/.mathpaste"
HS_DIR="$HOME/.hammerspoon"
HS_LUA="$HS_DIR/mathpaste.lua"
HS_INIT="$HS_DIR/init.lua"
OLD_PLIST="$HOME/Library/LaunchAgents/$LABEL.plist"
remove_old_watcher() {
# Older mathpaste ran a launchd Cmd+C watcher — tear it down if present.
launchctl bootout "gui/$(id -u)/$LABEL" 2>/dev/null \
|| launchctl unload "$OLD_PLIST" 2>/dev/null || true
rm -f "$OLD_PLIST"
}
reload_hammerspoon() {
# Reload config if the CLI port is up; otherwise just (re)launch the app.
if command -v hs >/dev/null 2>&1 && hs -c 'hs.reload()' >/dev/null 2>&1; then
return
fi
open -g -a Hammerspoon 2>/dev/null || true
}
if [ "${1:-}" = "--uninstall" ]; then
remove_old_watcher
rm -f "$HS_LUA"
# drop our require lines from init.lua, leave the rest of the user's config
if [ -f "$HS_INIT" ]; then
grep -v 'require("mathpaste")' "$HS_INIT" \
| grep -v 'require("hs.ipc")' > "$HS_INIT.tmp" || true
mv "$HS_INIT.tmp" "$HS_INIT"
fi
rm -rf "$OLD_INSTALL"
reload_hammerspoon
echo "mathpaste removed."
exit 0
fi
command -v hs >/dev/null 2>&1 || [ -d "/Applications/Hammerspoon.app" ] || {
echo "Hammerspoon is required: https://www.hammerspoon.org (brew install hammerspoon)"
exit 1
}
echo "Building the runtime venv in the repo -> $REPO/.venv"
remove_old_watcher
rm -rf "$OLD_INSTALL" # drop the legacy out-of-repo runtime copy
python3 -m venv "$REPO/.venv"
"$REPO/.venv/bin/pip" install --quiet --upgrade pip
"$REPO/.venv/bin/pip" install --quiet -r "$REPO/requirements.txt"
echo "Wiring the hotkey (Cmd+Shift+V) via Hammerspoon"
mkdir -p "$HS_DIR"
cp "$REPO/hammerspoon/mathpaste.lua" "$HS_LUA"
touch "$HS_INIT"
grep -q 'require("hs.ipc")' "$HS_INIT" || \
printf '%s\n' 'require("hs.ipc") -- enables the `hs` command-line scripting port' >> "$HS_INIT"
grep -q 'require("mathpaste")' "$HS_INIT" || \
printf '%s\n' 'require("mathpaste")' >> "$HS_INIT"
reload_hammerspoon
echo "Done. Copy LaTeX, press Cmd+Shift+V in Word to convert and paste."
echo " uninstall: ./setup --uninstall"