-
Notifications
You must be signed in to change notification settings - Fork 0
/
HOMELY.py
136 lines (107 loc) · 5.23 KB
/
HOMELY.py
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
#! /usr/bin/env python3
import os
import pathlib
import sys
import homely.files as files
import homely.system as system
HERE = os.path.dirname(os.path.realpath(__file__))
def main():
# Better handle if XDG_CONFIG_HOME is unset or empty (during initial bootstrap)
default_config_home = "$HOME/.config"
config_home = os.getenv("XDG_CONFIG_HOME", default_config_home) or default_config_home
# TODO to auto rename to an "x.old" and warn?
files.symlink("bashrc", ".bashrc")
files.symlink("bash_profile", ".bash_profile")
files.symlink("profile", ".profile") # TODO maybe add lines instead?
files.symlink("editorconfig", ".editorconfig")
if system.haveexecutable("latexmk"):
files.symlink("latexmkrc", ".latexmkrc")
if system.haveexecutable("task"):
files.symlink("taskrc", ".taskrc")
if system.haveexecutable("asdf"):
files.symlink("tool-versions", ".tool-versions")
files.symlink("asdfrc", ".asdfrc")
files.symlink("default-golang-pkgs", ".default-golang-pkgs")
# git common config:
# TODO error if git not present
# TODO into separate function
gitpath = os.path.join(HERE, "common.gitconfig")
system.execute(["git", "config", "--global", "include.path", gitpath])
# NOTE this might overwrite if there's another include.path already present
# TODO revert/cleanup somehow?
# TODO check that path specification using ~/ works
# global git ignore
files.mkdir(f"{config_home}/git")
files.symlink("git-ignore", f"{config_home}/git/ignore")
# TODO does pipinstall use system pip or HOMELY's one?
files.symlink("vimrc", ".vimrc")
# install vim-plug
files.mkdir(".vim")
files.mkdir(".vim/autoload")
files.mkdir(".vim/swaps")
files.mkdir(".vim/backups")
files.mkdir(".vim/doc")
files.download(
"https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim",
"~/.vim/autoload/plug.vim",
)
# link custom ftplugin files
files.symlink("vim-ftplugin", ".vim/ftplugin")
# link custom ftdetect files
files.symlink("vim-ftdetect", ".vim/ftdetect")
# Font config
files.mkdir(f"{config_home}/fontconfig")
files.symlink("fonts.conf", f"{config_home}/fontconfig/fonts.conf")
if system.haveexecutable("pipenv"):
# TODO warn that they need to reload for this to take effect
files.lineinfile(".bashrc.local", 'eval "$(pipenv --completion)"')
if system.haveexecutable("i3"):
# ~/.local/bin is towards the front of PATH thanks to .profile
files.symlink("i3exit.sh", "~/.local/bin/i3exit")
files.symlink("locker.sh", "~/.local/bin/locker")
files.symlink("i3.conf", "~/.i3/config")
if system.haveexecutable("zathura"):
conf_dir = pathlib.Path(f"{config_home}/zathura")
files.mkdir(str(conf_dir))
files.symlink("zathurarc", str(conf_dir / "zathurarc"))
if system.haveexecutable("sway"):
sway_dest_dir = pathlib.Path(f"{config_home}/sway")
files.mkdir(str(sway_dest_dir))
files.symlink("sway/config", str(sway_dest_dir / "config"))
dest_conf_d = sway_dest_dir / "config.d"
files.mkdir(str(dest_conf_d))
# Symlink all content from sway/config.d to ~/sway/config.d
# Rather than symlinking the directory itself, to allow for local-machine inclusions
for i in pathlib.Path(HERE, "sway/config.d").iterdir():
files.symlink(str(i), str(dest_conf_d / i.name))
dest_scripts_dir = sway_dest_dir / "scripts"
files.mkdir(str(dest_scripts_dir))
for i in pathlib.Path(HERE, "sway/scripts").iterdir():
files.symlink(str(i), str(dest_scripts_dir / i.name))
if system.haveexecutable("waybar"):
waybar_dest_dir = pathlib.Path(config_home, "waybar")
files.mkdir(str(waybar_dest_dir))
files.symlink("waybar/config", str(waybar_dest_dir / "config"))
files.symlink("waybar/style.css", str(waybar_dest_dir / "style.css"))
files.mkdir(str(waybar_dest_dir / "scripts"))
for i in pathlib.Path(HERE, "waybar/scripts").iterdir():
files.symlink(str(i), str(waybar_dest_dir / "scripts" / i.name))
if system.haveexecutable("kitty"):
files.mkdir(f"{config_home}/kitty")
files.symlink("kitty.conf", f"{config_home}/kitty/kitty.conf")
if system.haveexecutable("alacritty"):
files.mkdir(f"{config_home}/alacritty")
files.symlink("alacritty.yml", f"{config_home}/alacritty/alacritty.yml")
if system.haveexecutable("pre-commit"):
# Install pre-commit in all new/cloned repos
# See also https://pre-commit.com/#pre-commit-init-templatedir
template_path = "{}/.git-template".format(os.environ["HOME"])
system.execute(["git", "config", "--global", "init.templateDir", template_path])
system.execute(["pre-commit", "init-templatedir", template_path])
if system.haveexecutable("chromium"):
files.symlink("chromium-flags.conf", f"{config_home}/chromium-flags.conf")
# TODO does electron do the hints too, or should this only be installed when wayland is present?
files.symlink("electron-flags.conf", f"{config_home}/electron-flags.conf")
return 0
if __name__ in ("__main__", "HOMELY"):
sys.exit(main())