-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.py
63 lines (51 loc) · 1.76 KB
/
bootstrap.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
#!/bin/python3
import os
import pathlib
import shutil
def removeDirTree(dirpath):
# tries to remove tree; if failed show exception
try:
shutil.rmtree(dirpath)
except OSError as e:
print("Error:%s - %s." % (e.filename, e.strerror))
def removeFile(filepath):
# tries to remove file; if failed show exception
try:
os.remove(filepath)
except OSError as e:
print("Error:%s - %s." % (e.filename, e.strerror))
def removeLink(linkpath):
# tries to remove file; if failed show exception
try:
os.unlink(linkpath)
except OSError as e:
print("Error:%s - %s." % (e.filename, e.strerror))
def main():
# os path variables
home = os.environ['HOME']
config = home + "/.config"
repo_dir = pathlib.Path(__file__).parent.resolve().as_posix()
# dict to map src files (repo) to dest files (links)
destinations = {
repo_dir + "/nvim" : config + "/nvim",
repo_dir + "/alacritty" : config + "/alacritty",
repo_dir + "/tmux.conf" : home + "/.tmux.conf",
}
print("This may overwrite existing files in your home directory. Are you sure? (y/n)")
ans = input()
if(ans.lower() == "y"):
for src in destinations:
dest = destinations[src]
# Check if the dest is a link, a file or a dir and delete it
if(os.path.islink(dest)):
removeLink(dest)
elif(os.path.isfile(dest)):
removeFile(dest)
elif(os.path.isdir(dest)):
removeDirTree(dest)
# creates the symbolic link
os.symlink(src, dest)
print(src + " -> " + dest)
print("Links created successfully!")
if __name__ == "__main__":
main()