-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.py
More file actions
executable file
·146 lines (126 loc) · 4.92 KB
/
setup.py
File metadata and controls
executable file
·146 lines (126 loc) · 4.92 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
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.13"
# dependencies = [
# "tomli-w",
# ]
# ///
#
# ↑ PEP 723のinline script metadataってやつ uv runとかで実行すると仮想環境作って入れて実行してくれるらしい
import sys
import os
from pathlib import Path
from typing import Any
# import subprocess
import tomli_w
script_dir = Path(__file__).parent
argv = sys.argv[1:]
force = '--force' in argv
home = Path.home()
config_home = Path(os.getenv("XDG_CONFIG_HOME", home / '.config'))
cache_home = Path(os.getenv("XDG_CACHE_HOME", home / '.cache'))
data_home = Path(os.getenv("XDG_DATA_HOME", home / '.local' / 'share'))
binary_path = home / '.local' / 'bin'
uname = os.uname()
def main():
make_symlink('dunst', config_home)
make_symlink('fd', config_home)
make_symlink('fish', config_home, True)
make_symlink('fontconfig', config_home)
make_symlink('ghostty/config', config_home) # themeをうっかり入れるとライセンス違反になる
make_symlink('clipse', config_home)
make_symlink('git', config_home)
make_symlink('jj/config.toml', config_home)
make_symlink('jj/conf.d', config_home)
make_symlink('containers/containers.conf.d/00-common.conf', config_home)
make_symlink('niri', config_home)
make_symlink('npm', config_home)
make_symlink('gtk-3.0', config_home)
make_symlink('ideavim', config_home)
if (kanshi_config := script_dir / 'kanshi' / uname.nodename).exists():
make_symlink('kanshi/config', config_home, target=kanshi_config)
make_symlink('karabiner', config_home, True)
make_symlink('latexmk', config_home, True)
make_symlink('lazygit', config_home, True)
make_symlink('nvim', config_home)
make_symlink('ripgrep', config_home)
make_symlink('.satysfi/local/packages',
home,
target=script_dir / 'satysfi' / 'packages')
make_symlink('libskk', config_home, True, target=script_dir / 'skk' / 'libskk')
make_symlink('systemd/user', config_home, True)
make_symlink('tmux', config_home, True)
make_symlink('elephant', config_home)
make_symlink('walker', config_home, True)
make_symlink('waybar', config_home)
make_symlink('xremap', config_home)
make_symlink('zathura', config_home)
make_symlink('glide', config_home)
make_symlink('.clang-format', home)
make_symlink('.mutagen.yml', home)
make_symlink('.myclirc', home)
make_symlink('.zshenv', home)
make_symlink('.zshrc', home)
make_symlink('fzf-preview.sh', binary_path)
make_symlink('env-sync.zsh', binary_path)
make_symlink('fzfrc', config_home)
make_symlink('lesskey', config_home)
make_symlink('starship.toml', config_home)
make_symlink('nb', config_home)
make_symlink('mimeapps.list', config_home)
write_file(config_home / 'wgetrc', [
f'hsts-file = {cache_home / 'wget-hsts'}'
])
write_file(home / '.indentconfig.yaml', [
f'paths:',
f' - {script_dir / 'latexindent' / 'setting.yaml'}'
])
# WSLとかでフォントサイズいじりたいので
neovide_config: dict[str, Any] = { "fork": True, 'title-hidden': True }
if uname.sysname == 'Darwin':
neovide_config['frame'] = 'buttonless'
write_file(config_home / 'neovide' / 'config.toml', tomli_w.dumps(neovide_config))
def write_file(path: Path, lines: str | list[str]):
lines = lines if isinstance(lines, list) else [lines]
if not path.parent.exists():
path.parent.mkdir(parents=True, exist_ok=True)
if path.exists():
print(f"{path} exists. Skipped.")
return
with open(path, 'w') as f:
print(*lines, sep='\n', file=f)
print(f"Created: {path}", file=sys.stderr)
def make_symlink(name: str | os.PathLike,
link_base: Path,
recursive=False,
*,
target: str | os.PathLike | None = None):
link = link_base / name
if not link.parent.exists():
link.parent.mkdir(parents=True, exist_ok=True)
if link.exists():
if link.is_dir(follow_symlinks=False):
# symlinkでないディレクトリ: recursiveなら中身で判定。そうでなければreturn
if not recursive:
print(f"{link} exists. Skipped.")
return
elif force:
# fileかsymlink: forece
link.unlink()
else:
print(f"{link} exists. Skipped.")
return
if target is None:
target = script_dir / name
else:
target = Path(target)
if target.is_dir() and recursive:
for p in target.iterdir():
link_path = Path(name, p.name)
target_path = target / p.name
make_symlink(link_path, link_base, True, target=target_path)
else:
link.symlink_to(target, target_is_directory=True)
print(f"Linked: {link} -> {target}", file=sys.stderr)
if __name__ == '__main__':
main()