Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 102 lines (84 sloc) 2.569 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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
#!/usr/bin/env python
import os
import shutil
import sys

home = os.path.expanduser('~') + '/'
files = {
'bash/bashrc': '.bashrc',
'bash/bash_profile': '.bash_profile',
'vim/vimrc': '.vimrc',
'git/gitconfig': '.gitconfig',
'git/gitignore_global': '.gitignore_global',
'hg/hgrc': '.hgrc',
    'mongo/mongorc.js': '.mongorc.js',
'vrapperrc': '.vrapperrc'
}

linux_files = {
    'bash/bashrc_linux': '.bashrc_platfom'
}

mac_files = {
    'bash/bashrc_macosx': '.bashrc_platform'
}

def get_backup_dir():
backup_dir = home + ".dotfiles_backup%d"
for i in range(100):
t = backup_dir % i
if not os.path.exists(t):
return t + "/"
raise ValueError("No backup dir possible")
backup_dir = get_backup_dir()

def main():
print "Setting up config files..."
handle_confs(files)

handle_os_specific_conf()

install_vim_packages()
print ""
print "Now run:"
print " vim +BundleInsall +qall"
print "to finish with installing the vim packages"

def handle_confs(conf_dict):
for src, dest in conf_dict.iteritems():
handle_conf(src, dest)

def handle_conf(src, dest):
abssrc = os.path.abspath(src)
target = home + dest
parentDir = os.path.abspath(os.path.join(target, os.pardir))
if not os.path.exists(parentDir):
print "! Ignore: Could not find parent directory for %s" % target
return
if os.path.exists(target):
if os.path.islink(target):
os.remove(target)
else:
backup_existing_file(target)

os.symlink(abssrc, target)

print "+ %s => %s" % (target, abssrc)

def backup_existing_file(target):
ensure_backup_dir()
print "backing up %s, saved in %s" % (target, backup_dir)
shutil.move(target, backup_dir + os.path.basename(target))

def ensure_backup_dir():
if not os.path.exists(backup_dir):
os.mkdir(backup_dir)

def handle_os_specific_conf():
if sys.platform == "linux2":
print "Setting up conf files for Linux..."
handle_confs(linux_files)
if sys.platform == "darwin":
print "Setting up conf files for Mac OS X..."
handle_confs(mac_files)

def install_vim_packages():
print "installing vim packages with vundle..."
vim_home = home + '.vim'
bundle_home = vim_home + '/bundle'
if not os.path.exists(vim_home):
os.mkdir(vim_home)
if not os.path.exists(bundle_home):
os.mkdir(bundle_home)
os.system("git clone https://github.com/gmarik/vundle %s/vundle" %bundle_home)

syntax_dir = home + '.vim/syntax_checkers'
if not os.path.exists(syntax_dir):
print "Setting up Syntastic syntax checkers..."
os.symlink(bundle_home + '/syntastic/syntax_checkers', syntax_dir)

if __name__ == "__main__":
main()
Something went wrong with that request. Please try again.