-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·104 lines (86 loc) · 2.89 KB
/
install
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
#!/usr/bin/env python3
"""
A simple dotfile-installing script.
This file was written by Damien Dart, <[email protected]>. This is
free and unencumbered software released into the public domain. For
more information, please refer to the accompanying "UNLICENCE" file.
"""
import hashlib
import os
import pathlib
import subprocess
import sys
import textwrap
files = [
".bash_aliases",
".bash_profile",
".bashrc",
".config/git/config",
".config/git/ignore",
".config/nvim/init.vim",
".ideavimrc",
".profile",
".shellrc",
".tmux.conf",
".vim/after/ftplugin",
".vim/after/plugin",
".vim/after/syntax",
".vim/doc",
".vim/pack",
".vim/plugin",
".vimrc",
]
notice = """
If any shell-related dotfiles have changed, you may need to log out and
log back in, or "source" any new dotfiles so that they take effect in
the current interactive shell session.
""".rstrip()
vim_tags = [
".vim/doc/tags",
".vim/pack/plugins/start/editorconfig-vim/doc/tags",
".vim/pack/plugins/start/fzf/doc/tags",
]
if __name__ == "__main__":
errors = False
for file in files:
destination = pathlib.Path(pathlib.Path.home(), file)
source = pathlib.Path(sys.path[0], file).resolve()
if os.path.exists(destination):
if os.path.samefile(destination.resolve(), source):
print('[-] Link to "{}" already exists'.format(source))
else:
print('[✘] "{}" already exists'.format(destination))
errors = True
else:
if os.path.islink(destination):
print('[✘] "{}" is a dangling symlink'.format(destination))
errors = True
else:
if "/" in file:
os.makedirs(os.path.dirname(destination), 0o700, True)
os.symlink(source, destination)
print('[✔] Created link to "{}"'.format(source))
for tag in vim_tags:
tag_checksum = None
tag_file = pathlib.Path(pathlib.Path.home(), tag)
if os.path.exists(tag_file):
tag_checksum = hashlib.sha256(tag_file.read_bytes()).digest()
try:
subprocess.check_output(
'vim --not-a-term "+helptags {} | q"'.format(
os.path.dirname(tag_file),
),
shell=True,
stderr=subprocess.STDOUT,
)
if tag_checksum == hashlib.sha256(tag_file.read_bytes()).digest():
print('[-] "{}" is already up-to-date'.format(tag_file))
else:
print('[✔] Generated "{}"'.format(tag_file))
except subprocess.CalledProcessError as e:
print('[✘] Unable to generate "{}"'.format(tag_file))
print(textwrap.indent(e.output.decode().strip(), " "))
errors = True
print(notice)
if errors:
sys.exit(1)