summaryrefslogtreecommitdiff
path: root/bin/dot
diff options
context:
space:
mode:
authorUrbain Vaes <urbain@vaes.uk>2016-03-08 19:03:17 +0000
committerUrbain Vaes <urbain@vaes.uk>2016-03-08 19:03:17 +0000
commit810035ab675fbf35a79bb9b1f23619ad696e9183 (patch)
treed39d7e896acdde0d09762b09733fd9b471ae8372 /bin/dot
parent18fec99e540705c159a1b786122453446dc3a469 (diff)
Improve install file
Diffstat (limited to 'bin/dot')
-rwxr-xr-xbin/dot103
1 files changed, 47 insertions, 56 deletions
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