-
Notifications
You must be signed in to change notification settings - Fork 0
/
makeSymlinks
executable file
·68 lines (53 loc) · 1.95 KB
/
makeSymlinks
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
#!/usr/bin/env python
"""
Creates symlinks in the home directory to the files in this folder
Based on
http://blog.smalleycreative.com/tutorials/using-git-and-github-to-manage-your-dotfiles/
"""
import os, shutil
home = os.path.expanduser("~")
repoDir = os.path.dirname(os.path.realpath(__file__))
originalOldDir = os.path.join(home, "dotFilesOld")
# List of files/folders to symlink in homedir
files = [\
"bashrc" ,\
"vimrc" ,\
"conkyrc" ,\
"conky" ,\
"tmux.conf" ,\
os.path.join("vim", "spell"),\
]
fileRepo = [os.path.join(repoDir, f) for f in files]
fileHome = [os.path.join(home, "."+f) for f in files]
# Check that the paths exists
for folder in fileHome:
if not os.path.exists(folder):
os.makedirs(folder)
print("{} did not exist in advance, so the script created it".\
format(folder))
# Create backupdir in home
nr = 1
oldDir = originalOldDir
while(os.path.exists(oldDir)):
oldDir = originalOldDir + str(nr)
nr += 1
os.makedirs(oldDir)
print("Creating {} for backup of any existing dotfiles in {}".format(oldDir, home))
fileBkup = [os.path.join(oldDir, "."+f) for f in files]
print("...done\n")
print("Moving any existing dotfiles in home to dotfilesOld directory\n")
for fHome, fBkup in zip(fileHome, fileBkup):
if os.path.exists(fHome):
print("Moving {} -> {}".format(fHome, fBkup))
if os.path.isdir(fHome):
if not os.path.exists(fBkup):
os.makedirs(fBkup)
shutil.move(fHome, os.path.join(fBkup+'*'))
print("\nCreating symlinks\n")
for fRepo, fHome in zip(fileRepo, fileHome):
print("Symlinking to {} -> {}".format(fRepo, fHome))
if os.path.isdir(fRepo):
target_is_directory = True
else:
target_is_directory = False
os.symlink(fRepo, fHome, target_is_directory=target_is_directory)