#!/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 sort .dotmap -o .dotmap } $1