-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·349 lines (312 loc) · 11.1 KB
/
install.sh
File metadata and controls
executable file
·349 lines (312 loc) · 11.1 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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
#!/bin/sh
# CodeSlobCleanup Skill Installation Script
# Repository: https://github.com/Jazz23/CodeSlobCleanup
# Exit on error
set -e
# Ensure common paths are in PATH
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:$HOME/.local/bin:$PATH"
echo "Starting CodeSlobCleanup skill installation..."
# Helper: read from terminal even when piped (curl | sh)
read_tty() {
prompt="$1"
var_name="$2"
if [ -t 0 ]; then
printf "%s" "$prompt"
read _val
else
printf "%s" "$prompt" > /dev/tty
read _val < /dev/tty
fi
eval "$var_name=\$_val"
}
# 1. Check for any existing installations across all known locations
EXISTING_COUNT=0
EXISTING_NAME_1="" EXISTING_PATH_1=""
EXISTING_NAME_2="" EXISTING_PATH_2=""
EXISTING_NAME_3="" EXISTING_PATH_3=""
EXISTING_NAME_4="" EXISTING_PATH_4=""
EXISTING_NAME_5="" EXISTING_PATH_5=""
EXISTING_NAME_6="" EXISTING_PATH_6=""
add_existing() {
EXISTING_COUNT=$((EXISTING_COUNT + 1))
eval "EXISTING_NAME_${EXISTING_COUNT}=\"\$1\""
eval "EXISTING_PATH_${EXISTING_COUNT}=\"\$2\""
}
get_existing_name() { eval "printf '%s' \"\$EXISTING_NAME_${1}\""; }
get_existing_path() { eval "printf '%s' \"\$EXISTING_PATH_${1}\""; }
for _entry in \
"Claude Code (global):$HOME/.claude/skills" \
"Gemini CLI (global):$HOME/.gemini/skills" \
"Codex CLI (global):$HOME/.codex/skills" \
"Claude Code (local):$PWD/.claude/skills" \
"Gemini CLI (local):$PWD/.gemini/skills" \
"Codex CLI (local):$PWD/.agents/skills"; do
_name="${_entry%%:*}"
_path="${_entry#*:}"
if [ -d "$_path/code-slob-cleanup" ]; then
add_existing "$_name" "$_path"
fi
done
# SKIP_TO_INSTALL=1 means we resolved targets here; skip the normal install picker below
SKIP_TO_INSTALL=0
SKILLS_DIRS=""
INSTALLED_NAMES=""
# Helper: build selected paths/names from a which-prompt over the existing list
# Sets _selected_paths and _selected_names
pick_existing() {
_prompt="$1"
_all_opt=$((EXISTING_COUNT + 1))
_none_opt=$((EXISTING_COUNT + 2))
_i=1
while [ "$_i" -le "$EXISTING_COUNT" ]; do
printf " %d) %s\n" "$_i" "$(get_existing_name "$_i")"
_i=$((_i + 1))
done
printf " %d) All of the above\n" "$_all_opt"
printf " %d) None\n" "$_none_opt"
read_tty "$_prompt [1-${_none_opt}]: " _which
_selected_paths=""
_selected_names=""
case "$_which" in
''|*[!0-9]*) echo "Invalid choice, skipping." ;;
*)
if [ "$_which" -eq "$_all_opt" ]; then
_i=1
while [ "$_i" -le "$EXISTING_COUNT" ]; do
_selected_paths="$_selected_paths $(get_existing_path "$_i")"
_selected_names="$_selected_names$(get_existing_name "$_i"), "
_i=$((_i + 1))
done
_selected_paths=$(echo "$_selected_paths" | sed 's/^ //')
_selected_names=$(echo "$_selected_names" | sed 's/, $//')
elif [ "$_which" -eq "$_none_opt" ]; then
:
elif [ "$_which" -ge 1 ] && [ "$_which" -le "$EXISTING_COUNT" ]; then
_selected_paths=$(get_existing_path "$_which")
_selected_names=$(get_existing_name "$_which")
else
echo "Choice out of range, skipping."
fi
;;
esac
}
if [ "$EXISTING_COUNT" -eq 1 ]; then
echo ""
printf "Found existing installation in %s.\n" "$(get_existing_name 1)"
echo " 1) Update"
echo " 2) Remove"
read_tty "Enter choice [1-2]: " _action
case "$_action" in
1)
SKILLS_DIRS=$(get_existing_path 1)
INSTALLED_NAMES=$(get_existing_name 1)
SKIP_TO_INSTALL=1
;;
2)
rm -rf "$(get_existing_path 1)/code-slob-cleanup"
printf "Removed from %s.\n" "$(get_existing_name 1)"
echo "Re-run this script if you wish to reinstall!"
exit 0
;;
*)
echo "Invalid choice. Aborting."; exit 1
;;
esac
elif [ "$EXISTING_COUNT" -gt 1 ]; then
echo ""
echo "Found existing installations in:"
_i=1
while [ "$_i" -le "$EXISTING_COUNT" ]; do
printf " %d) %s\n" "$_i" "$(get_existing_name "$_i")"
_i=$((_i + 1))
done
echo ""
echo "What would you like to do?"
echo " 1) Update"
echo " 2) Remove"
read_tty "Enter choice [1-2]: " _action
case "$_action" in
1)
echo ""
pick_existing "Which to update?"
if [ -n "$_selected_paths" ]; then
SKILLS_DIRS="$_selected_paths"
INSTALLED_NAMES="$_selected_names"
SKIP_TO_INSTALL=1
else
echo "Nothing selected, exiting."
exit 0
fi
;;
2)
echo ""
pick_existing "Which to remove?"
if [ -n "$_selected_paths" ]; then
for _p in $_selected_paths; do
rm -rf "$_p/code-slob-cleanup"
done
echo "Removed."
echo "Re-run this script if you wish to reinstall!"
exit 0
else
echo "Nothing selected, exiting."
exit 0
fi
;;
*)
echo "Invalid choice. Aborting."; exit 1
;;
esac
fi
# 2. Check for uv and install if not already installed
if ! command -v uv > /dev/null 2>&1; then
echo "uv not found. Installing uv..."
curl -LsSf https://astral.sh/uv/install.sh | sh
if [ -f "$HOME/.cargo/env" ]; then
. "$HOME/.cargo/env"
fi
export PATH="$HOME/.local/bin:$PATH"
else
echo "uv is already installed."
fi
if [ "$SKIP_TO_INSTALL" -ne 1 ]; then
# 3. Ask: global or local install?
echo ""
echo "Install scope:"
echo " 1) Global — available in all projects (~/.claude, ~/.gemini, ~/.codex)"
echo " 2) Local — current project only"
read_tty "Enter choice [1/2] (default: 2): " INSTALL_SCOPE
case "$INSTALL_SCOPE" in
1) INSTALL_SCOPE="global" ;;
*) INSTALL_SCOPE="local" ;;
esac
echo "Installing $INSTALL_SCOPE..."
# 4. Determine target skills directories
DETECTED_COUNT=0
AGENT_NAME_1="" AGENT_PATH_1=""
AGENT_NAME_2="" AGENT_PATH_2=""
AGENT_NAME_3="" AGENT_PATH_3=""
add_agent() {
DETECTED_COUNT=$((DETECTED_COUNT + 1))
eval "AGENT_NAME_${DETECTED_COUNT}=\"\$1\""
eval "AGENT_PATH_${DETECTED_COUNT}=\"\$2\""
}
get_agent_name() { eval "printf '%s' \"\$AGENT_NAME_${1}\""; }
get_agent_path() { eval "printf '%s' \"\$AGENT_PATH_${1}\""; }
pick_agents() {
if [ "$DETECTED_COUNT" -eq 0 ]; then
echo "No supported AI coding tools detected (claude, gemini, codex)."
echo "Please install at least one of them, or re-run and choose local install."
exit 1
fi
if [ "$DETECTED_COUNT" -eq 1 ]; then
INSTALLED_NAMES=$(get_agent_name 1)
SKILLS_DIRS=$(get_agent_path 1)
return
fi
echo ""
echo "Multiple agents detected. Where would you like to install?"
i=1
while [ "$i" -le "$DETECTED_COUNT" ]; do
printf " %d) %s (%s)\n" "$i" "$(get_agent_name "$i")" "$(get_agent_path "$i")"
i=$((i + 1))
done
_all_opt=$((DETECTED_COUNT + 1))
printf " %d) All of the above\n" "$_all_opt"
read_tty "Enter choice [1-${_all_opt}]: " AGENT_CHOICE
SKILLS_DIRS=""
INSTALLED_NAMES=""
if [ "$AGENT_CHOICE" = "$_all_opt" ]; then
i=1
while [ "$i" -le "$DETECTED_COUNT" ]; do
SKILLS_DIRS="$SKILLS_DIRS $(get_agent_path "$i")"
INSTALLED_NAMES="$INSTALLED_NAMES$(get_agent_name "$i"), "
i=$((i + 1))
done
SKILLS_DIRS=$(echo "$SKILLS_DIRS" | sed 's/^ //')
INSTALLED_NAMES=$(echo "$INSTALLED_NAMES" | sed 's/, $//')
else
case "$AGENT_CHOICE" in
''|*[!0-9]*) echo "Invalid choice. Aborting."; exit 1 ;;
esac
if [ "$AGENT_CHOICE" -lt 1 ] || [ "$AGENT_CHOICE" -gt "$DETECTED_COUNT" ]; then
echo "Choice out of range. Aborting."; exit 1
fi
INSTALLED_NAMES=$(get_agent_name "$AGENT_CHOICE")
SKILLS_DIRS=$(get_agent_path "$AGENT_CHOICE")
fi
}
if [ "$INSTALL_SCOPE" = "global" ]; then
if [ -d "$HOME/.claude" ] || command -v claude > /dev/null 2>&1; then
add_agent "Claude Code" "$HOME/.claude/skills"
fi
if [ -d "$HOME/.gemini" ] || command -v gemini > /dev/null 2>&1; then
add_agent "Gemini CLI" "$HOME/.gemini/skills"
fi
if [ -d "$HOME/.codex" ] || command -v codex > /dev/null 2>&1; then
add_agent "Codex CLI" "$HOME/.codex/skills"
fi
pick_agents
else
for entry in ".claude:Claude Code" ".gemini:Gemini CLI" ".agents:Codex CLI"; do
dir="${entry%%:*}"
name="${entry#*:}"
if [ -d "$PWD/$dir" ]; then
add_agent "$name" "$PWD/$dir/skills"
fi
done
if [ "$DETECTED_COUNT" -eq 0 ]; then
echo "Neither .claude, .gemini, nor .agents folders were found in ($PWD)."
read_tty "Please enter the folder name to install into (e.g., .claude): " USER_DIR
case "$USER_DIR" in
/*) base="$USER_DIR" ;;
*) base="$PWD/$USER_DIR" ;;
esac
add_agent "$USER_DIR" "$base/skills"
fi
pick_agents
fi
fi # end SKIP_TO_INSTALL
# 5. Create skills directories
for d in $SKILLS_DIRS; do
if [ ! -d "$d" ]; then
echo "Creating directory: $d"
mkdir -p "$d"
fi
done
# 6. Get the files (Git clone or ZIP fallback)
TEMP_DIR=$(mktemp -d)
REPO_URL="https://github.com/Jazz23/CodeSlobCleanup"
if command -v git > /dev/null 2>&1; then
echo "Cloning CodeSlobCleanup repository..."
git clone --depth 1 "$REPO_URL.git" "$TEMP_DIR"
SKILL_SOURCE="$TEMP_DIR/skills/code-slob-cleanup"
else
echo "git not found. Attempting to download repository as ZIP..."
if command -v curl > /dev/null 2>&1 && command -v unzip > /dev/null 2>&1; then
ZIP_URL="$REPO_URL/archive/refs/heads/main.zip"
curl -LsSf "$ZIP_URL" -o "$TEMP_DIR/repo.zip"
unzip -q "$TEMP_DIR/repo.zip" -d "$TEMP_DIR"
SKILL_SOURCE="$TEMP_DIR/CodeSlobCleanup-main/skills/code-slob-cleanup"
else
echo "Error: Both git and curl/unzip are missing. Please install git or curl and unzip to continue."
rm -rf "$TEMP_DIR"
exit 1
fi
fi
# 7. Copy the skill into each target directory
if [ -d "$SKILL_SOURCE" ]; then
for d in $SKILLS_DIRS; do
rm -rf "$d/code-slob-cleanup"
cp -r "$SKILL_SOURCE" "$d/"
done
echo "Installed Code Slob Cleanup skill to ${INSTALLED_NAMES}!"
else
echo "Error: Could not find skills/code-slob-cleanup in the downloaded files."
rm -rf "$TEMP_DIR"
exit 1
fi
# 8. Cleanup
echo "Cleaning up temporary files..."
rm -rf "$TEMP_DIR"
echo "Done!"