-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall
More file actions
executable file
·255 lines (212 loc) · 8.27 KB
/
install
File metadata and controls
executable file
·255 lines (212 loc) · 8.27 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
#!/usr/bin/env python3
import argparse
import os
import shutil
import tarfile
from pathlib import Path
from subprocess import Popen, check_output
from tempfile import TemporaryDirectory
from typing import Final
from urllib.request import urlretrieve
from platform import python_version
NODE = "22"
RUBY = "3.4"
LUA = "5.1"
CODEX_EXCLUDE_SKILLS: Final[set[str]] = set()
SHARED_SKILLS_REPO: Final[str] = "default-anton/very-good-agent-skills"
SHARED_SKILLS_ARCHIVE_URL: Final[str] = (
f"https://codeload.github.com/{SHARED_SKILLS_REPO}/tar.gz/refs/heads/main"
)
SYM_LINKS: Final[list[tuple[str, str]]] = [
("~/.ripgreprc", "ripgreprc"),
("~/.gitconfig", "gitconfig"),
("~/.psqlrc", "psqlrc"),
("~/.sqliterc", "sqliterc"),
("~/.bash_aliases", "bash_aliases"),
("~/.tmux.conf", "tmux.conf"),
("~/.config/pgcli/config", "pgcli/config"),
("~/.config/nvim", "nvim"),
("~/.config/lazygit/config.yml", "lazygit.yml"),
("~/Library/Application Support/jesseduffield/lazygit/config.yml", "lazygit.yml"),
("~/.config/bat/config", "bat/config"),
("~/.config/starship.toml", "starship.toml"),
("~/.config/yabai", "config/yabai"),
("~/.config/skhd", "config/skhd"),
("~/.pi/agent/settings.json", "pi/agent/settings.json"),
("~/.pi/agent/models.json", "pi/agent/models.json"),
("~/.pi/agent/AGENTS.md", "pi/agent/AGENTS.md"),
("~/.pi/agent/prompts", "pi/agent/prompts"),
("~/.pi/agent/extensions", "pi/agent/extensions"),
("~/.pi/agent/skills", "pi/agent/skills"),
("~/.pi/agent/SYSTEM.md", "pi/agent/SYSTEM.md"),
("~/Library/Application Support/com.mitchellh.ghostty/config", "ghostty/config"),
("~/.codex/AGENTS.md", "codex/AGENTS.md"),
("~/.codex-api/AGENTS.md", "codex/AGENTS.md"),
("~/.codex/prompts", "codex/prompts"),
("~/.codex-api/prompts", "codex/prompts"),
("~/.claude/commands", "claude/commands"),
("~/.claude/settings.json", "claude/settings.json"),
("~/.claude/CLAUDE.md", "claude/CLAUDE.md"),
("~/.gemini/AGENTS.md", "gemini/AGENTS.md"),
("~/.gemini/settings.json", "gemini/settings.json"),
("~/.config/opencode/opencode.json", "opencode/opencode.json"),
]
COPY_FILES: Final[list[tuple[str, str]]] = [
("~/.codex/config.toml", "codex/config.toml"),
("~/.codex-api/config.toml", "codex/config.toml"),
]
TEMPLATES: Final[list[tuple[str, str]]] = [
("~/.config/alacritty/alacritty.toml", "alacritty.toml"),
]
DIRECTORIES: Final[list[str]] = [
"~/code",
]
DOTFILES: Path = Path("~/.dotfiles").expanduser()
SHELL_CMDS: Final[list[str]] = [
"brew bundle --no-upgrade",
f"$(brew --prefix)/bin/mise use --global node@{NODE} ruby@{RUBY} lua@{LUA}",
"echo ruff ty | xargs -n1 $(brew --prefix)/bin/uv tool install",
"pip3 install --break-system-packages --user pynvim",
"$(brew --prefix)/opt/fzf/install",
]
BASHRC_LINES: Final[list[str]] = [
"source ~/.dotfiles/bashrc",
]
BASH_PROFILE_LINES: Final[list[str]] = [
"source ~/.bashrc",
"source ~/.dotfiles/profile",
]
def copy_directory(src: Path, dst: Path):
print(f"rm -rf {dst}")
if dst.is_symlink() or dst.is_file():
dst.unlink(missing_ok=True)
elif dst.exists():
shutil.rmtree(dst)
dst.parent.mkdir(parents=True, exist_ok=True)
print(f"cp -cRp {src} {dst}")
shutil.copytree(src, dst, symlinks=True)
def rewrite_skill_md(dst: Path, codex: str):
skill_md = dst.joinpath("SKILL.md")
if skill_md.exists():
content = skill_md.read_text()
updated = content.replace(".pi", codex)
if updated != content:
skill_md.write_text(updated)
print(f"replaced .pi with {codex} in {skill_md}")
def install_skill(skill_dir: Path):
for codex in (".codex", ".codex-api"):
dst = Path(f"~/{codex}/skills").expanduser().joinpath(skill_dir.name)
copy_directory(skill_dir, dst)
rewrite_skill_md(dst, codex)
def iter_shared_skill_dirs(root: Path):
for path in sorted(root.iterdir()):
if path.is_dir() and path.joinpath("SKILL.md").exists():
yield path
def install_shared_skills() -> set[str]:
with TemporaryDirectory() as tmp_dir:
tmp_path = Path(tmp_dir)
archive_path = tmp_path.joinpath("shared-skills.tar.gz")
print(f"download {SHARED_SKILLS_ARCHIVE_URL} -> {archive_path}")
urlretrieve(SHARED_SKILLS_ARCHIVE_URL, archive_path)
extracted_dir = tmp_path.joinpath("shared-skills")
extracted_dir.mkdir()
with tarfile.open(archive_path) as archive:
archive.extractall(extracted_dir)
roots = [path for path in extracted_dir.iterdir() if path.is_dir()]
if len(roots) != 1:
raise RuntimeError(
f"expected one root directory in {archive_path}, found {len(roots)}"
)
shared_skills = set()
for skill_dir in iter_shared_skill_dirs(roots[0]):
shared_skills.add(skill_dir.name)
install_skill(skill_dir)
if not shared_skills:
raise FileNotFoundError(
f"no top-level skills with SKILL.md found in {SHARED_SKILLS_REPO}"
)
return shared_skills
def main():
major, minor, patch = map(int, python_version().split('.'))
assert major == 3, 'python 3 expected'
parser = argparse.ArgumentParser()
if minor >= 9:
parser.add_argument("--brew", action=argparse.BooleanOptionalAction)
parser.set_defaults(brew=True)
else:
parser.add_argument("--no-brew", dest='brew', action='store_false')
args = parser.parse_args()
os.environ["HOMEBREW_PREFIX"] = check_output(["brew", "--prefix"]).strip().decode()
if args.brew:
for cmd in SHELL_CMDS:
process = Popen(
cmd,
cwd=DOTFILES,
shell=True,
executable=os.getenv("SHELL"),
)
process.wait(timeout=3600)
for (src, dst) in SYM_LINKS:
src, dst = Path(src).expanduser(), DOTFILES.joinpath(dst)
src.parent.mkdir(parents=True, exist_ok=True)
print(f"ln -s {src} {dst}")
src.unlink(missing_ok=True)
src.symlink_to(dst, target_is_directory=dst.is_dir())
for (dst, src) in COPY_FILES:
dst, src = Path(dst).expanduser(), DOTFILES.joinpath(src)
print(f"rm -rf {dst}")
process = Popen(
f'rm -rf "{dst}"',
cwd=DOTFILES,
shell=True,
executable=os.getenv("SHELL"),
)
process.wait(timeout=3600)
dst.parent.mkdir(parents=True, exist_ok=True)
print(f"cp -cRp {src} {dst}")
process = Popen(
f'cp -cRp "{src}" "{dst}"',
cwd=DOTFILES,
shell=True,
executable=os.getenv("SHELL"),
)
process.wait(timeout=3600)
shared_skills = install_shared_skills()
# Copy local skills into ~/.codex/skills/ and ~/.codex-api/skills/.
skills_dir = DOTFILES.joinpath("pi/agent/skills")
if skills_dir.exists():
for skill_dir in skills_dir.iterdir():
if (
skill_dir.name in CODEX_EXCLUDE_SKILLS
or skill_dir.name in shared_skills
):
continue
install_skill(skill_dir)
for (dst, template) in TEMPLATES:
dst, template = Path(dst).expanduser(), DOTFILES.joinpath(template)
dst.parent.mkdir(parents=True, exist_ok=True)
dst.unlink(missing_ok=True)
process = Popen(
f'envsubst < "{template}" > "{dst}"',
cwd=DOTFILES,
shell=True,
executable=os.getenv("SHELL"),
)
process.wait(timeout=3600)
for directory in DIRECTORIES:
print(f"mkdir -p {directory}")
Path(directory).expanduser().mkdir(parents=True, exist_ok=True)
bashrc = Path("~/.bashrc").expanduser()
bashrc_content = bashrc.read_text()
with bashrc.open(mode="a") as f:
for bashrc_line in BASHRC_LINES:
if bashrc_line not in bashrc_content:
f.write(bashrc_line)
profile = Path("~/.bash_profile").expanduser()
profile_content = profile.read_text()
with profile.open(mode="a") as f:
for profile_line in BASH_PROFILE_LINES:
if profile_line not in profile_content:
f.write(profile_line)
if __name__ == "__main__":
main()