-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmacmd-autoopen.sh
More file actions
52 lines (44 loc) · 1.72 KB
/
Copy pathmacmd-autoopen.sh
File metadata and controls
52 lines (44 loc) · 1.72 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
#!/bin/bash
# Open newly written Markdown files in MacMD Viewer, in the background.
#
# Wired as a PostToolUse(Write) hook. Exits silently and successfully on every
# path that is not "a real .md file was just written on a Mac with MacMD
# installed", so it can never interrupt a session.
#
# The switch is two marker files, so that this plugin and the script served at
# macmdviewer.com/setup agree on the same convention:
#
# ~/.claude/.macmd-autoopen exists -> ON (the setup script's convention)
# ~/.claude/.macmd-autoopen-off exists -> OFF
# neither -> ON (installing the plugin is the opt-in)
set -uo pipefail
BUNDLE_ID="com.arthur.MarkdownViewer"
if [ ! -f "$HOME/.claude/.macmd-autoopen" ] \
&& [ -f "$HOME/.claude/.macmd-autoopen-off" ]; then
exit 0
fi
[ "$(uname -s)" = "Darwin" ] || exit 0
payload="$(cat)"
file="$(printf '%s' "$payload" | python3 -c 'import sys, json
try:
print(json.load(sys.stdin).get("tool_input", {}).get("file_path", ""))
except Exception:
pass' 2>/dev/null)"
[ -n "$file" ] || exit 0
case "$file" in
*.md|*.markdown) ;;
*) exit 0 ;;
esac
# Machinery, not documentation: agent memory, dependencies, build output, temp.
case "$file" in
*/memory/*|*/MEMORY.md|*/node_modules/*|*/vendor/*|*/.build/*|*/build/*|\
*/DerivedData/*|*/.next/*|*/dist/*|*/target/*|*/.venv/*|*/site-packages/*|\
/tmp/*|/private/tmp/*|/private/var/folders/*)
exit 0 ;;
esac
[ -f "$file" ] || exit 0
# -g keeps focus where it is: the file appears, the terminal keeps the cursor.
# If MacMD is not installed, `open` fails and the plugin is simply a no-op —
# no error, no message, nothing to uninstall.
/usr/bin/open -g -b "$BUNDLE_ID" "$file" >/dev/null 2>&1 || true
exit 0