-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathinstall_asupersync_skill_globally.sh
More file actions
228 lines (195 loc) · 5.47 KB
/
Copy pathinstall_asupersync_skill_globally.sh
File metadata and controls
228 lines (195 loc) · 5.47 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
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(
cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd
)"
SOURCE_DIR="${SCRIPT_DIR}"
CLAUDE_SKILLS_DIR="${HOME}/.claude/skills"
CODEX_SKILLS_DIR="${CODEX_HOME:-${HOME}/.codex}/skills"
GEMINI_SKILLS_DIR="${HOME}/.gemini/skills"
DRY_RUN=false
ASSUME_YES=false
usage() {
cat <<'EOF'
Install repo-local skills into detected global agent skill directories.
Usage:
./skills/install_asupersync_skill_globally.sh [--dry-run] [--yes]
Options:
--dry-run, -n Preview rsync operations without writing changes
--yes, -y Skip the confirmation prompt
--help, -h Show this help message
Notes:
- Installs skills from this repo's ./skills directory.
- Detects Claude Code, Codex, and Gemini using command/home-directory hints.
- Does not delete anything from destination directories.
- Uses rsync for additive/update mirroring only.
EOF
}
has_command() {
command -v "$1" >/dev/null 2>&1
}
append_target() {
local name="$1"
local dest="$2"
local reason="$3"
TARGET_NAMES+=("$name")
TARGET_DIRS+=("$dest")
TARGET_REASONS+=("$reason")
}
detect_targets() {
TARGET_NAMES=()
TARGET_DIRS=()
TARGET_REASONS=()
local reason=""
reason=""
if has_command "claude"; then
reason="detected \`claude\` command"
elif [[ -d "${HOME}/.claude" ]]; then
reason="detected ~/.claude home"
fi
if [[ -n "$reason" ]]; then
append_target "Claude Code" "$CLAUDE_SKILLS_DIR" "$reason"
fi
reason=""
if has_command "cod"; then
reason="detected \`cod\` command"
elif has_command "codex"; then
reason="detected \`codex\` command"
elif [[ -n "${CODEX_HOME:-}" ]]; then
reason="detected CODEX_HOME"
elif [[ -d "${HOME}/.codex" ]]; then
reason="detected ~/.codex home"
fi
if [[ -n "$reason" ]]; then
append_target "Codex" "$CODEX_SKILLS_DIR" "$reason"
fi
reason=""
if has_command "gmi"; then
reason="detected \`gmi\` command"
elif has_command "gemini"; then
reason="detected \`gemini\` command"
elif [[ -d "${HOME}/.gemini" ]]; then
reason="detected ~/.gemini home"
fi
if [[ -n "$reason" ]]; then
append_target "Gemini" "$GEMINI_SKILLS_DIR" "$reason"
fi
}
discover_skills() {
SKILL_DIRS=()
while IFS= read -r skill_dir; do
[[ -n "$skill_dir" ]] && SKILL_DIRS+=("$skill_dir")
done < <(
find "$SOURCE_DIR" \
-mindepth 1 \
-maxdepth 1 \
-type d \
-exec test -f "{}/SKILL.md" \; \
-print | sort
)
}
confirm() {
if $ASSUME_YES; then
return 0
fi
if [[ ! -t 0 ]]; then
echo "Refusing to install without confirmation from an interactive terminal." >&2
echo "Re-run with --yes if you want non-interactive execution." >&2
return 1
fi
local answer=""
printf "Proceed with global skill installation? [y/N] "
read -r answer
case "${answer}" in
y|Y|yes|YES)
return 0
;;
*)
echo "Aborted."
return 1
;;
esac
}
sync_targets() {
local rsync_flags=(-a --human-readable --itemize-changes)
if $DRY_RUN; then
rsync_flags=(-anv --human-readable --itemize-changes)
fi
local idx=0
local skill_dir=""
local skill_name=""
local target_dir=""
for idx in "${!TARGET_NAMES[@]}"; do
target_dir="${TARGET_DIRS[$idx]}"
mkdir -p "$target_dir"
echo
echo "==> ${TARGET_NAMES[$idx]} -> ${target_dir}"
for skill_dir in "${SKILL_DIRS[@]}"; do
skill_name="$(basename "$skill_dir")"
mkdir -p "${target_dir}/${skill_name}"
rsync "${rsync_flags[@]}" "${skill_dir}/" "${target_dir}/${skill_name}/"
done
done
}
main() {
while [[ $# -gt 0 ]]; do
case "$1" in
--dry-run|-n)
DRY_RUN=true
;;
--yes|-y)
ASSUME_YES=true
;;
--help|-h)
usage
exit 0
;;
*)
echo "Unknown option: $1" >&2
usage >&2
exit 1
;;
esac
shift
done
if ! has_command "rsync"; then
echo "rsync is required but not installed." >&2
exit 1
fi
discover_skills
if [[ "${#SKILL_DIRS[@]}" -eq 0 ]]; then
echo "No repo-local skills found under ${SOURCE_DIR}." >&2
exit 1
fi
detect_targets
if [[ "${#TARGET_NAMES[@]}" -eq 0 ]]; then
echo "No supported global agent installations detected." >&2
echo "Looked for Claude Code, Codex, and Gemini homes/commands." >&2
exit 1
fi
echo "Repo skill source: ${SOURCE_DIR}"
echo "Skills to install:"
for skill_dir in "${SKILL_DIRS[@]}"; do
echo " - $(basename "$skill_dir")"
done
echo "Detected agent targets:"
local idx=0
for idx in "${!TARGET_NAMES[@]}"; do
echo " - ${TARGET_NAMES[$idx]} -> ${TARGET_DIRS[$idx]} (${TARGET_REASONS[$idx]})"
done
if $DRY_RUN; then
echo "Mode: dry run"
else
echo "Mode: live install"
fi
echo "Safety: this script only adds/updates files; it does not delete destination content."
confirm
sync_targets
echo
if $DRY_RUN; then
echo "Dry run complete."
else
echo "Global skill installation complete."
fi
}
main "$@"