summaryrefslogtreecommitdiff
path: root/bin/dot
blob: 905e0c1ef03e472d8ed289ce44365a223f6513d5 (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
57
58
#!/usr/bin/env python

import os
import sys
import yaml

# Colors for terminal
from termcolor import colored


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

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

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

# All files in dir
normal_symlinks = set(os.listdir(dotpath)) - set(config['exclude'])


def perform(action):

    # Command to execute
    command = config['commands'][action]

    for f in special_symlinks | normal_symlinks:

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

        if f in config['pre']:
            print(config['pre'][f])
            os.system(config['pre'][f])

        # Target of symlink
        if f in special_symlinks:
            t = config['special'][f]
        elif f in normal_symlinks:
            t = config['default'].format(file=f)

        if t != "":
            # Formatted command
            formatted = command.format(file=f, path=dotpath, target=t)

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

        else:
            print("Nothing to do!")

        print('\n')

perform(sys.argv[1])