-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathzig-computer.distribute.sh
More file actions
executable file
·179 lines (159 loc) · 5.8 KB
/
Copy pathzig-computer.distribute.sh
File metadata and controls
executable file
·179 lines (159 loc) · 5.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
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
#!/usr/bin/env bash
# zig-computer.distribute.sh
#
# Distribute the dotfiles harness (skills, hooks, CLAUDE.md, optional
# settings) into a destination directory shaped like a coworker's
# `~/.claude/`. The destination ends up with:
#
# <dest>/
# CLAUDE.md <- copy of dotfiles/agents/AGENTS.md
# .claude/
# skills/<name>/SKILL.md (and supporting files)
# hooks/*.sh
# settings.json <- copy of dotfiles/claude/settings.json (optional)
#
# Default destination: ~/linearb/skills (a shared LinearB-team git repo).
#
# Usage:
# zig-computer.distribute.sh # distribute to ~/linearb/skills
# zig-computer.distribute.sh /path/to/dest # custom destination
# zig-computer.distribute.sh --dry-run # show what would happen
# zig-computer.distribute.sh --no-settings # skip settings.json
#
# The destination's existing CLAUDE.md / skills/ / hooks/ are wiped and
# replaced. settings.json is only overwritten when --settings is set
# (default: copy if missing, otherwise leave alone — settings tend to
# be coworker-specific).
set -euo pipefail
# ---- Parse args -------------------------------------------------------
DRY_RUN=0
COPY_SETTINGS="if-missing" # one of: always | if-missing | never
DEST=""
while [ $# -gt 0 ]; do
case "$1" in
--dry-run) DRY_RUN=1; shift ;;
--no-settings) COPY_SETTINGS="never"; shift ;;
--settings) COPY_SETTINGS="always"; shift ;;
-h|--help)
sed -n '2,30p' "$0" | sed 's/^# \?//'
exit 0
;;
-*)
echo "Unknown flag: $1" >&2
exit 1
;;
*)
if [ -n "$DEST" ]; then
echo "Multiple destinations given: '$DEST' and '$1'" >&2
exit 1
fi
DEST="$1"
shift
;;
esac
done
DEST="${DEST:-$HOME/linearb/skills}"
SRC="$(cd "$(dirname "$0")" && pwd)"
# ---- Verify source layout --------------------------------------------
for required in "$SRC/agents/AGENTS.md" "$SRC/agents/skills" "$SRC/agents/hooks"; do
if [ ! -e "$required" ]; then
echo "Source layout broken: missing $required" >&2
exit 1
fi
done
# ---- Resolve dest layout ---------------------------------------------
if [ ! -d "$DEST" ]; then
echo "Destination doesn't exist: $DEST" >&2
echo "Create it first (e.g., 'mkdir -p $DEST') or pass a path that does." >&2
exit 1
fi
DEST_CLAUDE_DIR="$DEST/.claude"
DEST_SKILLS_DIR="$DEST_CLAUDE_DIR/skills"
DEST_HOOKS_DIR="$DEST_CLAUDE_DIR/hooks"
DEST_CLAUDE_MD="$DEST/CLAUDE.md"
DEST_SETTINGS="$DEST_CLAUDE_DIR/settings.json"
# ---- Helpers ---------------------------------------------------------
run() {
if [ "$DRY_RUN" = "1" ]; then
echo " [dry-run] $*"
else
echo " $*"
eval "$@"
fi
}
note() { echo "$*"; }
# ---- Plan + execute --------------------------------------------------
note "=== zig-computer distribute ==="
note " source: $SRC"
note " dest: $DEST"
note " mode: $([ "$DRY_RUN" = "1" ] && echo dry-run || echo apply)"
note ""
note "[1/4] CLAUDE.md (from agents/AGENTS.md)"
run "cp '$SRC/agents/AGENTS.md' '$DEST_CLAUDE_MD'"
note "[2/4] skills/ (clean + copy paragon set)"
# Destination-native skills: a destination may maintain skills of its own
# that do NOT come from dotfiles (e.g. linearb-positioning in the LinearB
# team repo). List them one-per-line in <dest>/.claude/skills/.native-manifest
# and the clean step preserves them across distributes.
NATIVE_MANIFEST="$DEST_SKILLS_DIR/.native-manifest"
NATIVE_TMP=""
if [ -f "$NATIVE_MANIFEST" ]; then
NATIVE_TMP="$(mktemp -d)"
note " preserving destination-native skills (.native-manifest):"
while IFS= read -r native; do
case "$native" in ''|'#'*) continue;; esac
if [ -d "$DEST_SKILLS_DIR/$native" ]; then
note " - $native"
run "cp -R '$DEST_SKILLS_DIR/$native' '$NATIVE_TMP/$native'"
fi
done < "$NATIVE_MANIFEST"
run "cp '$NATIVE_MANIFEST' '$NATIVE_TMP/.native-manifest'"
fi
run "rm -rf '$DEST_SKILLS_DIR'"
run "mkdir -p '$DEST_SKILLS_DIR'"
run "cp -R '$SRC/agents/skills/.' '$DEST_SKILLS_DIR/'"
if [ -n "$NATIVE_TMP" ]; then
run "cp -R '$NATIVE_TMP/.' '$DEST_SKILLS_DIR/'"
run "rm -rf '$NATIVE_TMP'"
fi
# Strip private-reference blocks from the DISTRIBUTED copies only —
# pointers to machine-local files (~/linearb/refs/..., personal paths)
# that a coworker's clone can't resolve. Convention: everything between
# <!-- private-start --> and <!-- private-end --> (inclusive) is
# removed. The dotfiles originals keep the blocks.
run "find '$DEST_SKILLS_DIR' -name '*.md' -exec sed -i '/<!-- private-start -->/,/<!-- private-end -->/d' {} +"
note "[3/4] hooks/ (clean + copy)"
run "rm -rf '$DEST_HOOKS_DIR'"
run "mkdir -p '$DEST_HOOKS_DIR'"
run "cp -R '$SRC/agents/hooks/.' '$DEST_HOOKS_DIR/'"
note "[4/4] settings.json"
SETTINGS_SRC="$SRC/claude/settings.json"
if [ ! -f "$SETTINGS_SRC" ]; then
note " (no settings.json in source — skipping)"
elif [ "$COPY_SETTINGS" = "never" ]; then
note " (--no-settings — skipping)"
elif [ "$COPY_SETTINGS" = "always" ]; then
run "mkdir -p '$DEST_CLAUDE_DIR'"
run "cp '$SETTINGS_SRC' '$DEST_SETTINGS'"
elif [ -f "$DEST_SETTINGS" ]; then
note " (dest already has settings.json — leaving alone; pass --settings to overwrite)"
else
run "mkdir -p '$DEST_CLAUDE_DIR'"
run "cp '$SETTINGS_SRC' '$DEST_SETTINGS'"
fi
note ""
note "=== summary ==="
if [ "$DRY_RUN" = "1" ]; then
note " dry-run only — no changes made"
else
SKILL_COUNT=$(/usr/bin/find "$DEST_SKILLS_DIR" -name SKILL.md 2>/dev/null | wc -l)
HOOK_COUNT=$(/usr/bin/find "$DEST_HOOKS_DIR" -type f 2>/dev/null | wc -l)
note " $SKILL_COUNT skills, $HOOK_COUNT hooks distributed to $DEST"
note ""
note " Next steps for the destination repo:"
note " cd '$DEST'"
note " git status"
note " git diff"
note " git add -A && git commit -m ':outbox_tray: distribute: sync from dotfiles'"
note " git push"
fi