-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.sh
More file actions
executable file
·121 lines (100 loc) · 3.17 KB
/
Copy pathupdate.sh
File metadata and controls
executable file
·121 lines (100 loc) · 3.17 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
#!/bin/bash
# Claude Workflow Updater
# Incrementally updates .claude/commands and .claude/template from GitHub
# Only overwrites files that are new or have changed upstream
set -e
REPO_URL="https://github.com/fucaot/Claude-workflow"
REPO_BRANCH="main"
TEMP_DIR=$(mktemp -d)
TARGET_DIR=".claude"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
NC='\033[0m'
NEW_COUNT=0
UPDATED_COUNT=0
SKIPPED_COUNT=0
NEW_FILES=()
UPDATED_FILES=()
SKIPPED_FILES=()
echo -e "${GREEN}Claude Workflow Updater${NC}"
echo "================================"
echo ""
# Verify .claude exists
if [ ! -d "$TARGET_DIR" ]; then
echo -e "${YELLOW}.claude directory not found. Run install.sh first.${NC}"
exit 1
fi
# Clone latest
echo -e "${CYAN}Fetching latest from GitHub...${NC}"
git clone --depth 1 --branch "$REPO_BRANCH" "$REPO_URL" "$TEMP_DIR/repo" > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e "${RED}Failed to clone repository. Check your internet connection.${NC}"
rm -rf "$TEMP_DIR"
exit 1
fi
echo -e "${GREEN}Repository fetched.${NC}"
echo ""
# Backup dir for overwritten files
backup_dir="$TARGET_DIR/backup_$(date +%Y%m%d_%H%M%S)"
# Create backup dir only when needed
NEED_BACKUP=false
update_category() {
local src_dir="$1"
local dst_dir="$2"
local label="$3"
echo -e "${CYAN}── ${label} ──${NC}"
if [ ! -d "$src_dir" ]; then
echo -e "${RED} Source directory not found, skipping.${NC}"
echo ""
return
fi
mkdir -p "$dst_dir"
for src_file in "$src_dir"/*; do
[ -e "$src_file" ] || continue
local fname=$(basename "$src_file")
local dst_file="$dst_dir/$fname"
if [ ! -f "$dst_file" ]; then
# NEW
cp "$src_file" "$dst_file"
echo -e " ${GREEN}+ ${fname}${NC} (new)"
NEW_COUNT=$((NEW_COUNT + 1))
NEW_FILES+=("$label/$fname")
elif ! diff -q "$src_file" "$dst_file" > /dev/null 2>&1; then
# UPDATED
if [ "$NEED_BACKUP" = false ]; then
mkdir -p "$backup_dir"
NEED_BACKUP=true
fi
mkdir -p "$backup_dir/$label"
cp "$dst_file" "$backup_dir/$label/$fname"
cp "$src_file" "$dst_file"
echo -e " ${YELLOW}~ ${fname}${NC} (updated, backup: $backup_dir)"
UPDATED_COUNT=$((UPDATED_COUNT + 1))
UPDATED_FILES+=("$label/$fname")
else
# UNCHANGED
echo -e " ${GREEN}= ${fname}${NC} (unchanged)"
SKIPPED_COUNT=$((SKIPPED_COUNT + 1))
SKIPPED_FILES+=("$label/$fname")
fi
done
echo ""
}
update_category "$TEMP_DIR/repo/commands" "$TARGET_DIR/commands" "commands"
update_category "$TEMP_DIR/repo/template" "$TARGET_DIR/template" "template"
# Summary
echo "================================"
echo -e "${GREEN}Update complete!${NC}"
echo ""
echo -e " ${GREEN}New: ${NEW_COUNT}${NC}"
echo -e " ${YELLOW}Updated: ${UPDATED_COUNT}${NC}"
echo -e " ${CYAN}Unchanged: ${SKIPPED_COUNT}${NC}"
if [ "$NEED_BACKUP" = true ]; then
echo ""
echo -e "${YELLOW}Backup of overwritten files: $backup_dir${NC}"
fi
# Cleanup
rm -rf "$TEMP_DIR"