From 810035ab675fbf35a79bb9b1f23619ad696e9183 Mon Sep 17 00:00:00 2001 From: Urbain Vaes Date: Tue, 8 Mar 2016 19:03:17 +0000 Subject: Improve install file --- bin/dot | 103 +++++++++++++++++++++++++++++----------------------------------- 1 file changed, 47 insertions(+), 56 deletions(-) (limited to 'bin') diff --git a/bin/dot b/bin/dot index 2e94da1..210c967 100755 --- a/bin/dot +++ b/bin/dot @@ -1,56 +1,47 @@ -#!/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]) +#!/usr/bin/env bash + +get_links() +{ + find $HOME -not -path "$HOME/dotfiles/*" -type l | while read line; do + if [[ "$(realpath -q $line)" == "${HOME}/dotfiles/"* ]]; then + echo $line + fi + done +} + +clean() +{ + get_links | while read link; do + rm -v ${link} + done +} + +down() +{ + source $HOME/dotfiles/.dotmap + for link in "${!dotmap[@]}"; do + echo "Removing ${link}." + rm -rf $link + done +} + +up() +{ + source $HOME/dotfiles/.dotmap + for link in "${!dotmap[@]}"; do + target=${dotmap[$link]} + mkdir -p $(dirname ${link}) + echo "Linking $target." + rm -rf $link && ln -s $target $link + done +} + +save() +{ + echo "declare -A dotmap" > .dotmap + get_links | while read link; do + echo "dotmap[$link]=$(realpath -q $link)" >> .dotmap + done +} + +$1 -- cgit v1.2.3