#!/usr/bin/env python3

import os
import sys
from subprocess import Popen, PIPE

here = os.path.dirname(sys.argv[0])
if here.startswith('./'):
    here = os.getcwd() + here[1:]

def install_file(src, dst):
    source = '%s/%s' % (here, src)
    dest = '%s/%s' % (os.environ['HOME'], dst)
    if os.path.exists(dest):
        sys.stdout.write('Skipping %s\n' % dst)
    else:
        sys.stdout.write('Installing %s\n' % dst)
        if not os.path.exists(os.path.dirname(dest)):
            os.makedirs(os.path.dirname(dest))
        Popen(['ln', '-s', source, dest]).wait()

files = [
        ('bash_aliases', '.bash_aliases'),
        ('bash_aliases.d', '.bash_aliases.d'),
        ('bash_profile', '.bash_profile'),
        ('profile', '.profile'),
        ('inputrc', '.inputrc'),
        ('screenrc', '.screenrc'),
        ('gitignore', '.gitignore'),
        ('colordiffrc', '.colordiffrc'),
        ('rvmrc', '.rvmrc'),
        ('toprc', '.toprc'),
        ('ctags', '.ctags'),
        ]

for s, d in files:
    install_file(s, d)
