Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 3a3e9b5a92
Fetching contributors…

Cannot retrieve contributors at this time

executable file 59 lines (48 sloc) 1.732 kb
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Link dotfiles to HOME dir.
"""
from __future__ import print_function, unicode_literals
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
from datetime import datetime
import os
import os.path
import shutil
import sys
__author__ = ('thomas.vandoren@gmail.com',)
def parse_args():
parser = ArgumentParser(description='Link dotfiles to home dir.',
formatter_class=ArgumentDefaultsHelpFormatter)
parser.add_argument('-d', '--dir', default=os.path.expanduser('~'),
help='Home directory to create links to dotfiles.')
return parser.parse_args()
_suffix = datetime.now().strftime('%Y%m%d%H%M%S')
def link(src, dst):
if os.path.exists(src):
src_bak = '{0}.{1}'.format(src, _suffix)
print('Backing up {0} to {1}.'.format(src, src_bak))
shutil.move(src, src_bak)
print('{0} -> {1}'.format(src, dst))
os.symlink(dst, src)
def link_all(home_dir):
cwd = os.path.abspath(os.path.dirname(__file__))
home_dir = os.path.abspath(home_dir)
all_dotfiles = filter(lambda d: d not in ['.git', '.gitignore'],
filter(lambda f: f.startswith('.'),
os.listdir(cwd)))
for filename in all_dotfiles:
src = os.path.join(home_dir, filename)
dst = os.path.join(cwd, filename)
link(src, dst)
def install():
try:
args = parse_args()
home_dir = args.dir.rstrip('/')
link_all(home_dir)
except Exception as ex:
print('Failure: {0}'.format(ex))
sys.exit(1)
print('Finished installing dotfiles.')
if __name__ == '__main__':
install()
Jump to Line
Something went wrong with that request. Please try again.