Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·380 lines (335 loc) · 12.1 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·380 lines (335 loc) · 12.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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
#!/bin/bash
# Agent Skills Installer
# One-command installation for AI coding assistants
set -e
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
# Defaults
REPO="MrGKanev/agent-skills"
BRANCH="master"
TARGET="claude" # claude, copilot, or cursor
INSTALL_ALIAS=false
LOCAL_INSTALL=false
show_help() {
echo "Agent Skills Installer"
echo ""
echo "Usage:"
echo " curl -fsSL https://raw.githubusercontent.com/$REPO/master/install.sh | bash"
echo " curl -fsSL https://raw.githubusercontent.com/$REPO/master/install.sh | bash -s -- [options]"
echo ""
echo "Options:"
echo " --target=TARGET Where to install: claude, copilot, cursor, all (default: claude)"
echo " --tag=TAG Install specific version/tag (default: latest)"
echo " --local Install from local repo instead of downloading from GitHub"
echo " --project Install to current project instead of global"
echo " --alias Add 'claud' shell alias for 'claude --dangerously-skip-permissions'"
echo " --list List available skills and exit"
echo " --help Show this help"
echo ""
echo "Examples:"
echo " # Install to Claude Code (global)"
echo " curl -fsSL https://raw.githubusercontent.com/$REPO/master/install.sh | bash"
echo ""
echo " # Install from local repo (includes my-skills)"
echo " ./install.sh --local"
echo ""
echo " # Install to current project for Copilot"
echo " curl -fsSL https://raw.githubusercontent.com/$REPO/master/install.sh | bash -s -- --target=copilot --project"
echo ""
echo " # Install specific version"
echo " curl -fsSL https://raw.githubusercontent.com/$REPO/master/install.sh | bash -s -- --tag=v1.0.0"
}
# Parse arguments
PROJECT_INSTALL=false
TAG=""
LIST_ONLY=false
for arg in "$@"; do
case $arg in
--target=*)
TARGET="${arg#*=}"
;;
--tag=*)
TAG="${arg#*=}"
BRANCH="$TAG"
;;
--project)
PROJECT_INSTALL=true
;;
--local)
LOCAL_INSTALL=true
;;
--alias)
INSTALL_ALIAS=true
;;
--list)
LIST_ONLY=true
;;
--help|-h)
show_help
exit 0
;;
esac
done
# Determine install directory
get_install_dir() {
local target=$1
local base_dir
if [ "$PROJECT_INSTALL" = true ]; then
base_dir="."
else
base_dir="$HOME"
fi
case $target in
claude)
echo "$base_dir/.claude"
;;
copilot|vscode)
echo "$base_dir/.github"
;;
cursor)
echo "$base_dir/.cursor"
;;
*)
echo "$base_dir/.claude"
;;
esac
}
# Install shell alias for Claude Code
install_claud_alias() {
local shell_config=""
local alias_line='alias claud="claude --dangerously-skip-permissions"'
# Detect shell config file
if [ -n "$ZSH_VERSION" ] || [ "$SHELL" = "/bin/zsh" ] || [ -f "$HOME/.zshrc" ]; then
shell_config="$HOME/.zshrc"
elif [ -n "$BASH_VERSION" ] || [ "$SHELL" = "/bin/bash" ] || [ -f "$HOME/.bashrc" ]; then
shell_config="$HOME/.bashrc"
fi
if [ -z "$shell_config" ]; then
echo -e "${YELLOW}Could not detect shell config file. Add manually:${NC}"
echo " $alias_line"
return 1
fi
# Check if alias already exists
if grep -q 'alias claud=' "$shell_config" 2>/dev/null; then
echo -e "${YELLOW}Alias 'claud' already exists in $shell_config${NC}"
return 0
fi
# Add alias to config file
echo "" >> "$shell_config"
echo "# Claude Code alias (skip permissions prompt)" >> "$shell_config"
echo "$alias_line" >> "$shell_config"
echo -e "${GREEN}Added alias 'claud' to $shell_config${NC}"
echo -e "${YELLOW}Run 'source $shell_config' or restart terminal to use it${NC}"
}
# Main installation
main() {
echo -e "${BLUE}Agent Skills Installer${NC}"
echo ""
# Determine source directory
if [ "$LOCAL_INSTALL" = true ]; then
# Find the repo root (where install.sh lives)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Verify this is a valid agent-skills repo
if [ ! -d "$SCRIPT_DIR/skills" ]; then
echo -e "${RED}Error: Not a valid agent-skills repository${NC}"
echo "Expected to find 'skills/' directory in $SCRIPT_DIR"
exit 1
fi
TEMP_DIR="$SCRIPT_DIR"
echo -e "${YELLOW}Installing from local repo...${NC}"
echo "Source: $SCRIPT_DIR"
else
# Create temp directory for download
TEMP_DIR=$(mktemp -d)
trap "rm -rf $TEMP_DIR" EXIT
echo -e "${YELLOW}Downloading skills...${NC}"
if [ -n "$TAG" ]; then
DOWNLOAD_URL="https://github.com/$REPO/archive/refs/tags/$TAG.tar.gz"
echo "Version: $TAG"
else
DOWNLOAD_URL="https://github.com/$REPO/archive/refs/heads/$BRANCH.tar.gz"
echo "Branch: $BRANCH"
fi
# Download and extract
curl -fsSL "$DOWNLOAD_URL" | tar -xz -C "$TEMP_DIR" --strip-components=1
fi
# List only mode
if [ "$LIST_ONLY" = true ]; then
echo ""
echo -e "${BLUE}Available skills:${NC}"
echo ""
echo -e "${GREEN}Upstream skills:${NC}"
for skill in "$TEMP_DIR"/skills/*/; do
if [ -f "${skill}SKILL.md" ]; then
echo " - $(basename "$skill")"
fi
done
echo ""
echo -e "${GREEN}Custom skills:${NC}"
if [ -d "$TEMP_DIR/my-skills" ]; then
found=false
for skill in "$TEMP_DIR"/my-skills/*/; do
if [ -d "$skill" ]; then
echo " - $(basename "$skill")"
found=true
fi
done
if [ "$found" = false ]; then
echo " (none)"
fi
fi
exit 0
fi
# Install to target(s)
install_to_target() {
local target=$1
local install_dir=$(get_install_dir "$target")
local skills_dir="$install_dir/skills"
echo -e "${YELLOW}Installing to $skills_dir...${NC}"
# Create directory
mkdir -p "$skills_dir"
# Copy skills
if [ -d "$TEMP_DIR/skills" ]; then
cp -r "$TEMP_DIR/skills"/* "$skills_dir/" 2>/dev/null || true
fi
# Copy my-skills
if [ -d "$TEMP_DIR/my-skills" ]; then
for skill in "$TEMP_DIR"/my-skills/*/; do
if [ -d "$skill" ]; then
cp -r "$skill" "$skills_dir/"
fi
done
fi
echo -e "${GREEN}Installed skills to: $skills_dir${NC}"
# Install safety features based on target
if [ -d "$TEMP_DIR/hooks" ]; then
case $target in
claude)
# Claude: Install executable hooks (real protection)
local hooks_dir="$install_dir/hooks"
echo -e "${YELLOW}Installing safety hooks to $hooks_dir...${NC}"
mkdir -p "$hooks_dir"
# Copy hook scripts
cp "$TEMP_DIR/hooks/"*.py "$hooks_dir/" 2>/dev/null || true
chmod +x "$hooks_dir/"*.py 2>/dev/null || true
# Merge or create settings.json with hooks config
local settings_file="$install_dir/settings.json"
local hooks_settings="$TEMP_DIR/hooks/settings.json"
if [ -f "$hooks_settings" ]; then
if [ -f "$settings_file" ]; then
cp "$settings_file" "$settings_file.backup"
echo -e "${YELLOW}Existing settings.json backed up${NC}"
python3 -c "
import json
try:
with open('$settings_file', 'r') as f:
existing = json.load(f)
except:
existing = {}
with open('$hooks_settings', 'r') as f:
hooks = json.load(f)
if 'hooks' not in existing:
existing['hooks'] = {}
for event, event_hooks in hooks.get('hooks', {}).items():
if event not in existing['hooks']:
existing['hooks'][event] = []
existing['hooks'][event].extend(event_hooks)
with open('$settings_file', 'w') as f:
json.dump(existing, f, indent=2)
" 2>/dev/null || cp "$hooks_settings" "$settings_file"
else
cp "$hooks_settings" "$settings_file"
fi
echo -e "${GREEN}Installed safety hooks (blocks destructive commands)${NC}"
fi
;;
copilot)
# Copilot: Add safety rules to instructions file
local instructions_file="$install_dir/copilot-instructions.md"
local safety_rules="$TEMP_DIR/hooks/SAFETY_RULES.md"
if [ -f "$safety_rules" ]; then
echo -e "${YELLOW}Installing safety rules to copilot-instructions.md...${NC}"
if [ -f "$instructions_file" ]; then
# Append to existing file if not already present
if ! grep -q "Git Safety Rules" "$instructions_file" 2>/dev/null; then
echo "" >> "$instructions_file"
cat "$safety_rules" >> "$instructions_file"
fi
else
cp "$safety_rules" "$instructions_file"
fi
echo -e "${GREEN}Installed safety rules (text-based guidance)${NC}"
fi
;;
cursor)
# Cursor: Add safety rules to rules file
local rules_dir="$install_dir/rules"
local safety_rules="$TEMP_DIR/hooks/SAFETY_RULES.md"
if [ -f "$safety_rules" ]; then
echo -e "${YELLOW}Installing safety rules to .cursor/rules...${NC}"
mkdir -p "$rules_dir"
cp "$safety_rules" "$rules_dir/git-safety.md"
echo -e "${GREEN}Installed safety rules (text-based guidance)${NC}"
fi
;;
esac
fi
}
if [ "$TARGET" = "all" ]; then
install_to_target "claude"
install_to_target "copilot"
install_to_target "cursor"
else
install_to_target "$TARGET"
fi
# Install shell alias if requested (only for Claude target)
if [ "$INSTALL_ALIAS" = true ]; then
if [ "$TARGET" = "claude" ] || [ "$TARGET" = "all" ]; then
echo ""
install_claud_alias
fi
fi
echo ""
echo -e "${GREEN}Installation complete!${NC}"
echo ""
# Show post-install info
case $TARGET in
claude)
echo "For Claude Code:"
echo " - Skills installed globally"
echo " - Safety hooks installed (blocks destructive git commands)"
echo ""
echo "Restart Claude Code to activate."
;;
copilot)
echo "For GitHub Copilot:"
echo " - Skills installed"
echo " - Safety rules added to copilot-instructions.md"
echo ""
echo "Note: Safety rules are text-based guidance only."
;;
cursor)
echo "For Cursor:"
echo " - Skills installed"
echo " - Safety rules added to .cursor/rules/"
echo ""
echo "Note: Safety rules are text-based guidance only."
;;
all)
echo "Installed to all targets:"
echo ""
echo "Claude Code:"
echo " - Safety hooks (blocks destructive commands)"
echo ""
echo "Copilot & Cursor:"
echo " - Safety rules (text-based guidance)"
echo ""
echo "Restart your IDE/editor to activate."
;;
esac
}
main "$@"