/
link.py
executable file
·34 lines (32 loc) · 1.1 KB
/
link.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
#!/usr/bin/env python
from __future__ import print_function
import os
import os.path
import platform
import sys
IGNORE_LIST = [
os.path.basename(__file__),
'.gitignore',
'README.mkdn',
'.git',
'DefaultKeyBinding.dict',
'U.S. International - Modified.keylayout',
'setup-osx.sh',
'lint.sh',
'.travis.yml',
]
if __name__ == '__main__':
dotfiles_fpath = os.path.dirname(os.path.abspath(__file__))
dotfiles = [f for f in os.listdir(dotfiles_fpath) if f not in IGNORE_LIST]
for dotfile in dotfiles:
src = os.path.join(dotfiles_fpath, dotfile)
dest = os.path.join(os.path.expanduser('~'), os.path.basename(dotfile))
if dotfile == '.Xdefaults': # .Xdefaults should be linked as .Xdefaults-hostname
dest += '-{}'.format(platform.node())
if os.path.lexists(dest):
if os.path.islink(dest):
os.remove(dest)
else:
print('{} already exists, you should remove it first!'.format(dest), file=sys.stderr)
print('symlinking {} to {}'.format(src, dest))
os.symlink(src, dest)