-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
executable file
·188 lines (147 loc) · 5.7 KB
/
Makefile
File metadata and controls
executable file
·188 lines (147 loc) · 5.7 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
.PHONY: help init apply diff update status check install test clean backup restore test-docker
# Default target
.DEFAULT_GOAL := help
# Variables
CHEZMOI := chezmoi
SOURCE_DIR := $(HOME)/.local/share/chezmoi
CONFIG_DIR := $(HOME)/.config/chezmoi
TESTING_DIR := $(SOURCE_DIR)/testing
help: ## Show this help message
@echo "Dotfiles Management - Makefile Commands"
@echo "========================================"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
init: ## Initialize chezmoi (clone dotfiles repo)
@echo "Initializing chezmoi..."
@if [ -d "$(SOURCE_DIR)/.git" ]; then \
echo "Dotfiles already initialized."; \
else \
echo "Enter your dotfiles repo URL:"; \
read repo_url; \
$(CHEZMOI) init $$repo_url; \
fi
apply: ## Apply dotfiles changes to the system
@echo "Applying dotfiles..."
$(CHEZMOI) apply -v
apply-force: ## Force apply all dotfiles (overwrite changes)
@echo "WARNING: This will overwrite any local changes!"
@echo "Press Ctrl+C to cancel, or Enter to continue..."
@read confirm
$(CHEZMOI) apply --force
diff: ## Show differences between current state and dotfiles
$(CHEZMOI) diff
update: ## Pull latest changes and apply
@echo "Updating dotfiles from remote..."
cd $(SOURCE_DIR) && git pull
$(CHEZMOI) apply -v
status: ## Show chezmoi status
$(CHEZMOI) status
check: ## Verify dotfiles without applying changes
$(CHEZMOI) apply --dry-run --verbose
install: ## Install dependencies (Homebrew, packages)
@echo "Installing dependencies..."
@if [ "$$(uname)" = "Darwin" ]; then \
if ! command -v brew >/dev/null 2>&1; then \
echo "Installing Homebrew..."; \
/bin/bash -c "$$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"; \
fi; \
echo "Running package installation script..."; \
$(CHEZMOI) apply --include scripts; \
elif [ -f /etc/arch-release ]; then \
echo "Running Arch Linux package installation..."; \
$(CHEZMOI) apply --include scripts; \
else \
echo "Running Linux package installation..."; \
$(CHEZMOI) apply --include scripts; \
fi
test: ## Test dotfiles in dry-run mode
@echo "Testing dotfiles (dry-run)..."
$(CHEZMOI) apply --dry-run --verbose
edit: ## Edit a dotfile with chezmoi
@echo "Enter filename to edit (e.g., .zshrc):"
@read filename; \
$(CHEZMOI) edit ~/$$filename
add: ## Add a file to chezmoi
@echo "Enter file path to add (absolute or relative to ~):"
@read filepath; \
$(CHEZMOI) add ~/$$filepath
remove: ## Remove a file from chezmoi management
@echo "Enter file to remove from chezmoi:"
@read filename; \
$(CHEZMOI) forget ~/$$filename
data: ## Show template data available to dotfiles
$(CHEZMOI) data
verify: ## Verify all dotfiles are correctly applied
$(CHEZMOI) verify
execute-template: ## Execute a template expression
@echo "Enter template expression (e.g., {{ .chezmoi.os }}):"
@read expr; \
$(CHEZMOI) execute-template "$$expr"
cd: ## Change to chezmoi source directory
@echo "Opening source directory..."
cd $(SOURCE_DIR) && $$SHELL
git-status: ## Show git status in source directory
@cd $(SOURCE_DIR) && git status
git-log: ## Show git log in source directory
@cd $(SOURCE_DIR) && git log --oneline --graph --decorate -10
commit: ## Commit changes to dotfiles repo
@echo "Enter commit message:"
@read msg; \
cd $(SOURCE_DIR) && git add -A && git commit -m "$$msg"
push: ## Push dotfiles changes to remote
@cd $(SOURCE_DIR) && git push
pull: ## Pull latest dotfiles from remote
@cd $(SOURCE_DIR) && git pull
backup: ## Backup current system configuration
@echo "Creating backup..."
@mkdir -p ~/dotfiles-backup-$$(date +%Y%m%d-%H%M%S)
@cp -r ~/.config ~/dotfiles-backup-$$(date +%Y%m%d-%H%M%S)/ 2>/dev/null || true
@cp -r ~/.ssh ~/dotfiles-backup-$$(date +%Y%m%d-%H%M%S)/ 2>/dev/null || true
@echo "Backup created in ~/dotfiles-backup-$$(date +%Y%m%d-%H%M%S)"
clean: ## Clean chezmoi cache and temporary files
@echo "Cleaning chezmoi cache..."
rm -rf ~/.cache/chezmoi
@echo "Cache cleaned."
doctor: ## Run chezmoi doctor to diagnose issues
$(CHEZMOI) doctor
lint: ## Lint shell scripts in dotfiles
@echo "Linting shell scripts..."
@find $(SOURCE_DIR) -name "*.sh" -type f -exec shellcheck {} \; || echo "shellcheck not installed"
packages-darwin: ## Install macOS packages only
@bash $(SOURCE_DIR)/run_onchange_before_install-packages-darwin.sh.tmpl
packages-linux: ## Install Linux packages only
@bash $(SOURCE_DIR)/run_onchange_before_install-packages-linux.sh.tmpl
setup-ssh: ## Generate SSH keys
@bash $(SOURCE_DIR)/run_once_after_02-generate-ssh-keys.sh.tmpl
setup-ohmyzsh: ## Install Oh My Zsh and Powerlevel10k
@bash $(SOURCE_DIR)/run_once_after_01-install-ohmyzsh.sh.tmpl
docs: ## Open documentation
@if [ -f "$(SOURCE_DIR)/README.md" ]; then \
cat $(SOURCE_DIR)/README.md; \
else \
echo "No README found"; \
fi
version: ## Show chezmoi and tool versions
@echo "Chezmoi version:"
$(CHEZMOI) --version
@echo "\nGit version:"
git --version
@if command -v brew >/dev/null 2>&1; then \
echo "\nHomebrew version:"; \
brew --version; \
fi
# Testing commands
test-docker: ## Run Docker-based integration tests
@echo "Running Docker-based tests..."
@cd $(TESTING_DIR) && $(MAKE) full-test
test-docker-build: ## Build Docker test environment
@cd $(TESTING_DIR) && $(MAKE) build
test-docker-up: ## Start Docker test containers
@cd $(TESTING_DIR) && $(MAKE) up
test-docker-down: ## Stop Docker test containers
@cd $(TESTING_DIR) && $(MAKE) down
test-docker-clean: ## Clean Docker test environment
@cd $(TESTING_DIR) && $(MAKE) clean
test-docker-shell: ## Open shell in test environment
@cd $(TESTING_DIR) && $(MAKE) shell
test-docker-verify: ## Verify test results
@cd $(TESTING_DIR) && $(MAKE) verify