summaryrefslogtreecommitdiff
path: root/bin/dot
blob: 2e94da1221ce2f88e62f28217e5c7351188a3921 (plain)
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
#!/usr/bin/env python

import os
import sys
import yaml

# Colors for terminal
from termcolor import colored

# Path of dotfiles
homepath = '/home/urbain'
dotpath = homepath + '/dotfiles'

# Load yaml configuration file
with open(dotpath + "/install.yaml", 'r') as stream:
    config = yaml.load(stream)

# Special and default symlinks
special_symlinks = set(config['special'].keys())
normal_symlinks = set(config['default'])


def perform(action):

    for f in special_symlinks | normal_symlinks:

        # Print filename
        print('[' + colored(f, 'green') + ']')

        if f in config['pre'] and action == 'up':

            # Format command
            command = config['pre'][f]
            formatted = command.format(file=f, path=dotpath)

            # Print & execute
            print(formatted)
            os.system(formatted)

        # Target of symlink
        if f in special_symlinks:
            t = config['special'][f]
        elif f in normal_symlinks:
            t = homepath + '/' + f

        # Command to execute
        command = config['commands'][action]
        formatted = command.format(file=f, path=dotpath, target=t)

        # Print & execute command
        print(formatted)
        os.system(formatted)

        print('\n')

perform(sys.argv[1])