-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall
More file actions
executable file
·201 lines (174 loc) · 6.82 KB
/
install
File metadata and controls
executable file
·201 lines (174 loc) · 6.82 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
#!/usr/bin/env python3
import argparse
import os
from pathlib import Path
from subprocess import Popen, check_output
from typing import Final
from platform import python_version
NODE = "22"
RUBY = "3.4"
LUA = "5.1"
CODEX_EXCLUDE_SKILLS: Final[set[str]] = set()
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 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)
# Dynamically copy all skills files from pi/agent/skills/ to ~/.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:
continue
for codex in (".codex", ".codex-api"):
dst = Path(f"~/{codex}/skills").expanduser().joinpath(skill_dir.name)
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 {skill_dir} {dst}")
process = Popen(
f'cp -cRp "{skill_dir}" "{dst}"',
cwd=DOTFILES,
shell=True,
executable=os.getenv("SHELL"),
)
process.wait(timeout=3600)
skill_md = dst.joinpath("SKILL.md")
if skill_md.exists():
content = skill_md.read_text()
updated = content.replace(".pi", codex)
skill_md.write_text(updated)
print(f"replaced .pi with {codex} in {skill_md}")
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()