-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcreate_symlink.py
More file actions
executable file
·51 lines (40 loc) · 1.41 KB
/
Copy pathcreate_symlink.py
File metadata and controls
executable file
·51 lines (40 loc) · 1.41 KB
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
#!/usr/bin/env python
# Script downloaded from:
# http://yiqiang.org/blog/2008/07/04/publishing-your-dotfiles/
import os, sys
def symlink(source, dest):
try:
print "Symlinking %s to %s" % (source, dest)
os.symlink(source, dest)
except Exception, msg:
print "Failed to symlink %s to %s " % (source, dest)
print msg
home = os.path.abspath(os.environ['HOME'])
path = os.path.join(home, '.dotfiles')
deep_dir_bases = ['gconf/apps']
excludes = ['gtk-2.0', 'create_symlink.py']
deep_dir_heads = [os.path.split(deep_dir)[0] for deep_dir in deep_dir_bases]
files = None
if len(sys.argv) > 1:
# Take options from the command line
files = sys.argv[1:]
else:
# Process all of the files
files = filter(lambda x: x not in deep_dir_heads, os.listdir(path))
files.extend(deep_dir_bases)
for f in files:
if f.startswith('.'):
continue
if f not in excludes and f not in deep_dir_heads:
src = os.path.abspath(f)
dst = os.path.join(home, '.' + f)
symlink(src, dst)
elif f in deep_dir_bases:
for dir in os.listdir(os.path.join(path, f)):
src = os.path.abspath(os.path.join(f, dir))
dst = os.path.join(home, '.' + f, dir)
symlink(src, dst)
elif os.path.join(os.path.split(f)[:-1]) in deep_dir_bases:
src = os.path.abspath(f)
dst = os.path.join(home, '.' + f)
symlink(src, dst)