-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
executable file
Β·214 lines (198 loc) Β· 8.25 KB
/
Copy pathMakefile
File metadata and controls
executable file
Β·214 lines (198 loc) Β· 8.25 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
# Modern Dotfiles Management with GNU Stow
# Configuration
STOW_DIR := src
TARGET_DIR := $(HOME)
PACKAGE := home
# Default target
.DEFAULT_GOAL := help
# Colors for output
NO_COLOR := \\033[0m
GREEN := \\033[32m
YELLOW := \\033[33m
BLUE := \\033[34m
RED := \\033[31m
# Helper function for colored output
define log
@echo "$(2)$(1)$(NO_COLOR)"
endef
.PHONY: help
help: ## Show this help message
@echo "$(BLUE)Modern Dotfiles Management$(NO_COLOR)"
@echo
@echo "$(YELLOW)Available targets:$(NO_COLOR)"
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " $(GREEN)%-15s$(NO_COLOR) %s\\n", $$1, $$2}' $(MAKEFILE_LIST)
.PHONY: setup
setup: ## Run complete setup script
$(call log,π Starting complete setup...,$(BLUE))
@if [ -f "./setup.sh" ]; then \
bash ./setup.sh; \
else \
echo "$(RED)β setup.sh not found$(NO_COLOR)"; \
exit 1; \
fi
.PHONY: diff
diff: ## Show differences between repo and home
$(call log,π Showing differences...,$(BLUE))
@for file in $$(find $(STOW_DIR)/$(PACKAGE) -type f -name ".*" 2>/dev/null); do \
relative_path=$${file#$(STOW_DIR)/$(PACKAGE)/}; \
home_file="$(TARGET_DIR)/$$relative_path"; \
if [ -f "$$home_file" ] && [ ! -L "$$home_file" ]; then \
echo "$(YELLOW)π $$relative_path$(NO_COLOR)"; \
diff -u "$$home_file" "$$file" || true; \
echo; \
fi; \
done
.PHONY: dry-run
dry-run: ## Preview stow changes without applying
$(call log,π― Previewing stow changes...,$(BLUE))
@stow -t $(TARGET_DIR) -d $(STOW_DIR) -v --simulate $(PACKAGE)
.PHONY: stow
stow: ## Apply dotfile symlinks (excludes .claude, use deploy for full setup)
$(call log,π Stowing dotfiles...,$(BLUE))
@stow -t $(TARGET_DIR) -d $(STOW_DIR) -v $(PACKAGE)
$(call log,β
Dotfiles stowed successfully,$(GREEN))
.PHONY: unstow
unstow: ## Remove dotfile symlinks
$(call log,ποΈ Unstowing dotfiles...,$(BLUE))
@stow -t $(TARGET_DIR) -d $(STOW_DIR) -v -D $(PACKAGE)
$(call log,β
Dotfiles unstowed successfully,$(GREEN))
.PHONY: restow
restow: ## Re-apply dotfile symlinks (unstow then stow)
$(call log,π Re-stowing dotfiles...,$(BLUE))
@stow -t $(TARGET_DIR) -d $(STOW_DIR) -v -R $(PACKAGE)
$(call log,β
Dotfiles re-stowed successfully,$(GREEN))
.PHONY: backup
backup: ## Backup existing dotfiles before stowing
$(call log,πΎ Backing up existing dotfiles...,$(BLUE))
@backup_dir="$$HOME/.dotfiles-backup-$$(date +%Y%m%d-%H%M%S)"; \
mkdir -p "$$backup_dir"; \
for file in $$(find $(STOW_DIR)/$(PACKAGE) -type f -name ".*" 2>/dev/null); do \
relative_path=$${file#$(STOW_DIR)/$(PACKAGE)/}; \
home_file="$(TARGET_DIR)/$$relative_path"; \
if [ -f "$$home_file" ] && [ ! -L "$$home_file" ]; then \
cp "$$home_file" "$$backup_dir/"; \
echo " π Backed up $$relative_path"; \
fi; \
done; \
$(call log,β
Backup created at $$backup_dir,$(GREEN))
.PHONY: clean
clean: ## Clean broken symlinks
$(call log,π§Ή Cleaning broken symlinks...,$(BLUE))
@find $(TARGET_DIR) -maxdepth 1 -name ".*" -type l ! -exec test -e {} \\; -exec rm -v {} \\;
$(call log,β
Broken symlinks cleaned,$(GREEN))
.PHONY: deploy
deploy: ## Backup conflicts and stow in one step
$(call log,π Deploying dotfiles...,$(BLUE))
@source scripts/setup-common.sh && \
backup_dotfiles_common && \
stow_dotfiles_common
$(call log,β
Deploy complete,$(GREEN))
.PHONY: validate
validate: ## Verify symlinks, shell syntax, and config integrity
$(call log,π Validating configuration...,$(BLUE))
@errors=0; \
echo "$(YELLOW)π Symlink health:$(NO_COLOR)"; \
for item in CLAUDE.md RTK.md settings.json hooks; do \
target="$(HOME)/.claude/$$item"; \
if [ -L "$$target" ]; then \
if [ -e "$$target" ]; then \
echo " β
~/.claude/$$item"; \
else \
echo " β ~/.claude/$$item (broken symlink)"; \
errors=$$((errors + 1)); \
fi; \
elif [ -e "$$target" ]; then \
echo " β οΈ ~/.claude/$$item (not a symlink)"; \
else \
echo " β ~/.claude/$$item (missing)"; \
errors=$$((errors + 1)); \
fi; \
done; \
if [ -L "$(HOME)/.config/hooksmith" ]; then \
if [ -e "$(HOME)/.config/hooksmith" ]; then \
echo " β
~/.config/hooksmith"; \
else \
echo " β ~/.config/hooksmith (broken symlink)"; \
errors=$$((errors + 1)); \
fi; \
fi; \
echo; \
echo "$(YELLOW)π Shell syntax:$(NO_COLOR)"; \
if zsh -n $(STOW_DIR)/$(PACKAGE)/.zshrc 2>/dev/null; then \
echo " β
.zshrc syntax OK"; \
else \
echo " β .zshrc has syntax errors"; \
errors=$$((errors + 1)); \
fi; \
if bash -n $(STOW_DIR)/$(PACKAGE)/.bashrc 2>/dev/null; then \
echo " β
.bashrc syntax OK"; \
else \
echo " β .bashrc has syntax errors"; \
errors=$$((errors + 1)); \
fi; \
echo; \
if [ $$errors -gt 0 ]; then \
echo "$(RED)β $$errors issue(s) found$(NO_COLOR)"; \
exit 1; \
else \
echo "$(GREEN)β
All checks passed$(NO_COLOR)"; \
fi
.PHONY: doctor
doctor: ## Diagnose common issues
$(call log,π₯ Running system diagnostics...,$(BLUE))
@echo "$(YELLOW)π Required tools:$(NO_COLOR)"
@command -v stow > /dev/null && echo " β
stow" || echo " β stow (brew install stow / apt install stow)"
@command -v git > /dev/null && echo " β
git" || echo " β git"
@command -v make > /dev/null && echo " β
make" || echo " β make"
@echo
@echo "$(YELLOW)π§ CLI tools:$(NO_COLOR)"
@command -v eza > /dev/null && echo " β
eza" || echo " β οΈ eza (brew install eza / cargo install eza)"
@command -v bat > /dev/null && echo " β
bat" || echo " β οΈ bat (brew install bat / apt install bat)"
@command -v rg > /dev/null && echo " β
ripgrep" || echo " β οΈ ripgrep (brew install ripgrep / apt install ripgrep)"
@command -v fd > /dev/null && echo " β
fd" || echo " β οΈ fd (brew install fd / apt install fd-find)"
@command -v fzf > /dev/null && echo " β
fzf" || echo " β οΈ fzf (brew install fzf / apt install fzf)"
@command -v jq > /dev/null && echo " β
jq" || echo " β οΈ jq (brew install jq / apt install jq)"
@command -v mise > /dev/null && echo " β
mise" || echo " β οΈ mise (brew install mise / curl https://mise.run | sh)"
@command -v claude > /dev/null && echo " β
claude" || echo " β οΈ claude (brew install claude-code / npm i -g @anthropic-ai/claude-code)"
@echo
@echo "$(YELLOW)π Checking directories:$(NO_COLOR)"
@[ -d "$(STOW_DIR)" ] && echo " β
$(STOW_DIR) exists" || echo " β $(STOW_DIR) missing"
@[ -d "$(STOW_DIR)/$(PACKAGE)" ] && echo " β
$(STOW_DIR)/$(PACKAGE) exists" || echo " β $(STOW_DIR)/$(PACKAGE) missing"
@[ -d "$(TARGET_DIR)" ] && echo " β
$(TARGET_DIR) exists" || echo " β $(TARGET_DIR) missing"
@echo
@echo "$(YELLOW)π Checking symlinks:$(NO_COLOR)"
@[ -L "$(HOME)/.zshrc" ] && echo " β
.zshrc linked" || echo " β οΈ .zshrc not linked"
@[ -L "$(HOME)/.gitconfig" ] && echo " β
.gitconfig linked" || echo " β οΈ .gitconfig not linked"
@[ -f "$(HOME)/.claude/settings.json" ] && echo " β
Claude settings exists" || echo " β οΈ Claude settings missing"
@echo
@echo "$(YELLOW)π€ Claude Code config:$(NO_COLOR)"
@for item in CLAUDE.md RTK.md settings.json hooks; do \
target="$(HOME)/.claude/$$item"; \
if [ -L "$$target" ]; then \
echo " β
$$item linked"; \
elif [ -e "$$target" ]; then \
echo " β οΈ $$item exists but is NOT a symlink (unmanaged)"; \
else \
echo " β $$item missing"; \
fi; \
done
@echo
@echo "$(YELLOW)πͺ Hooksmith:$(NO_COLOR)"
@if [ -L "$(HOME)/.config/hooksmith" ]; then \
echo " β
hooksmith config linked"; \
elif [ -d "$(HOME)/.config/hooksmith" ]; then \
echo " β οΈ hooksmith config exists but is NOT a symlink"; \
else \
echo " β hooksmith config missing"; \
fi
@command -v rtk > /dev/null && echo " β
rtk (token optimizer)" || echo " β οΈ rtk not installed"
@command -v python3 > /dev/null && python3 -c "import yaml" 2>/dev/null && echo " β
python3 + pyyaml (hooks dependency)" || echo " β οΈ python3 or pyyaml missing (workflow hooks need this)"
@echo
@echo "$(YELLOW)π§ Orchestrator:$(NO_COLOR)"
@if [ -n "$${ORCHESTRATOR_HOME:-}" ] && [ -d "$${ORCHESTRATOR_HOME}" ]; then \
echo " β
ORCHESTRATOR_HOME=$${ORCHESTRATOR_HOME}"; \
elif [ -d "$(HOME)/code/orchestrator" ]; then \
echo " β οΈ ORCHESTRATOR_HOME not set, but ~/code/orchestrator exists"; \
else \
echo " β ORCHESTRATOR_HOME not set and ~/code/orchestrator not found"; \
fi