From 83560b5b4ba00df1552d14150ec5d7930e2bdd0a Mon Sep 17 00:00:00 2001 From: Urbain Vaes Date: Sun, 17 Jan 2016 14:54:11 +0000 Subject: Improve install script --- bin/dot | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) (limited to 'bin/dot') diff --git a/bin/dot b/bin/dot index 905e0c1..2e94da1 100755 --- a/bin/dot +++ b/bin/dot @@ -7,51 +7,49 @@ import yaml # Colors for terminal from termcolor import colored - # Path of dotfiles -dotpath = '/home/urbain/dotfiles' +homepath = '/home/urbain' +dotpath = homepath + '/dotfiles' # Load yaml configuration file with open(dotpath + "/install.yaml", 'r') as stream: config = yaml.load(stream) -# Special symlinks +# Special and default symlinks special_symlinks = set(config['special'].keys()) - -# All files in dir -normal_symlinks = set(os.listdir(dotpath)) - set(config['exclude']) +normal_symlinks = set(config['default']) 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]) + 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 = config['default'].format(file=f) - - if t != "": - # Formatted command - formatted = command.format(file=f, path=dotpath, target=t) + t = homepath + '/' + f - # Print & execute command - print(formatted) - os.system(formatted) + # Command to execute + command = config['commands'][action] + formatted = command.format(file=f, path=dotpath, target=t) - else: - print("Nothing to do!") + # Print & execute command + print(formatted) + os.system(formatted) print('\n') -- cgit v1.2.3