Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
150 lines (123 loc) · 4.83 KB
/
Copy pathMakefile
File metadata and controls
150 lines (123 loc) · 4.83 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
DOTFILES := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
DEFAULT_SHELL := $(shell dscl . -read ~/ UserShell | sed 's/UserShell: //') # only works on mac
export STOW_DIR = $(DOTFILES)
export XDG_CONFIG_HOME = $(HOME)/.config
all: \
brew \
brew-packages \
link \
ssh-setup \
gpg-setup \
git-setup \
go-setup \
rust-setup \
bun-setup \
npm-setup
brew:
which brew || ( \
/bin/bash -c "$$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" && \
touch $$HOME/.zprofile && \
echo >> $$HOME/.zprofile && \
echo 'eval "$$(/opt/homebrew/bin/brew shellenv)"' >> $$HOME/.zprofile && \
eval "$(/opt/homebrew/bin/brew shellenv)" && \
brew update \
)
brew-packages: brew
brew bundle --file=$(DOTFILES)/Brewfile || true
stow: brew
which stow || brew install stow
link: link-runcoms link-config link-bin link-gnupg link-zshrc-local
# $HOME/.zshrc escape hatch.
#
# ZDOTDIR is set to ~/.config/zsh, so zsh never sources $HOME/.zshrc. But dumb
# tools hardcode $HOME/.zshrc and inject machine-specific lines there. We point
# $HOME/.zshrc at a gitignored local file so those writes (a) take effect via
# our config, which sources config/zsh/.zshrc.local, and (b) never land in the
# committed tree. The .local file is created empty if absent.
link-zshrc-local:
touch $(DOTFILES)/config/zsh/.zshrc.local
if [ -e $(HOME)/.zshrc -a ! -h $(HOME)/.zshrc ]; then \
mv -v $(HOME)/.zshrc $(HOME)/.zshrc.bak; \
fi
ln -sfn $(DOTFILES)/config/zsh/.zshrc.local $(HOME)/.zshrc
tmux-tpm-update:
set -e; \
TPM_DIR="$$HOME/.local/share/tmux/plugins/tpm"; \
mkdir -p "$${TPM_DIR%/tpm}"; \
if [ -d "$$TPM_DIR/.git" ]; then \
git -C "$$TPM_DIR" pull --ff-only; \
else \
rm -rf "$$TPM_DIR"; \
git clone https://github.com/tmux-plugins/tpm "$$TPM_DIR"; \
fi
$(HOME)/bin:
mkdir -p "$@"
# swarm: TS agent-orchestration tool compiled to a standalone binary via bun.
# Built from src/swarm; output is gitignored and stowed like other bin/ tools.
bin/swarm: src/swarm/swarm.ts $(wildcard src/swarm/*.ts)
which bun || (echo "bun not found, please install Bun first" && exit 1)
cd $(DOTFILES)/src/swarm && bun install
cd $(DOTFILES) && bun build --compile --outfile bin/swarm src/swarm/swarm.ts
swarm: bin/swarm
link-bin: stow bin/swarm bin/* $(HOME)/bin
stow -t $(HOME)/bin bin
link-runcoms: stow runcoms/.*
for FILE in $$(\ls -A runcoms); do if [ -f $(HOME)/$$FILE -a ! -h $(HOME)/$$FILE ]; then \
mv -v $(HOME)/$$FILE{,.bak}; fi; \
done
stow -t $(HOME) runcoms
link-config: stow config/*
mkdir -p $(XDG_CONFIG_HOME)
stow -t $(XDG_CONFIG_HOME) config
# Claude Code has no XDG fallback: .zshenv points CLAUDE_CONFIG_DIR at the
# stowed package, and $(HOME)/.claude is aliased to it so the hardcoded path
# every tool and doc still uses resolves to the same single state dir.
if [ -e $(HOME)/.claude -a ! -h $(HOME)/.claude ]; then \
mv -v $(HOME)/.claude $(HOME)/.claude.bak; \
fi
ln -sfn $(XDG_CONFIG_HOME)/claude $(HOME)/.claude
unlink-runcoms: stow
stow --delete -t $(HOME) runcoms
for FILE in $$(\ls -A runcoms); do if [ -f $(HOME)/$$FILE.bak ]; then \
mv -v $(HOME)/$$FILE.bak $(HOME)/$${FILE%%.bak}; fi; done
link-gnupg: stow gnupg/.gnupg/gpg-agent.conf
mkdir -p $(HOME)/.gnupg
chmod 700 $(HOME)/.gnupg
if [ -f $(HOME)/.gnupg/gpg-agent.conf -a ! -h $(HOME)/.gnupg/gpg-agent.conf ]; then \
mv -v $(HOME)/.gnupg/gpg-agent.conf $(HOME)/.gnupg/gpg-agent.conf.bak; \
fi
stow -t $(HOME) gnupg
chmod 600 $(HOME)/.gnupg/gpg-agent.conf
gpgconf --kill gpg-agent || true
unlink-gnupg: stow
stow --delete -t $(HOME) gnupg
if [ -f $(HOME)/.gnupg/gpg-agent.conf.bak ]; then \
mv -v $(HOME)/.gnupg/gpg-agent.conf.bak $(HOME)/.gnupg/gpg-agent.conf; \
fi
ssh-setup: ~/.ssh/id_ed25519
~/.ssh/id_ed25519:
# Generate a new ssh key for each new machine, if not already present.
ssh-keygen -t ed25519
gpg-setup: brew-packages link-gnupg .gpg-key-generated
.gpg-key-generated:
gpg --full-generate-key
touch .gpg-key-generated # do this once per machine
git-setup: brew-packages config/git/signingkey.inc config/git/email.inc
config/git/signingkey.inc: .gpg-key-generated
git config --file $(DOTFILES)/config/git/signingkey.inc user.signingkey \
$$(gpg --list-secret-keys --keyid-format LONG --with-colons | awk -F: '/^sec:/ { print $$5 }' | head -n1)
config/git/email.inc:
ifndef EMAIL
$(error EMAIL is undefined)
endif
git config --file $(DOTFILES)/config/git/email.inc user.email "$$EMAIL"
go-setup: brew-packages
rust-setup: brew-packages
rustup component add rust-analyzer
rustup component add rustfmt
bun-setup: brew-packages
which bun || (echo "bun not found, please install Bun first" && exit 1)
cat $(DOTFILES)/bun-global-packages.txt | xargs -I {} bun add -g {}
npm-setup: brew-packages
which npm || (echo "npm not found, please install Node.js first" && exit 1)
cat $(DOTFILES)/npm-global-packages.txt | xargs -I {} npm install -g {}