#!/usr/bin/env bash # A symlink cleanup script. # # Usage: clean [-du] # # Options: # -d Do a dry run (only output commands, no changes) # -u Uninstall all enabled topics _run() { [[ $DRYRUN ]] && echo "$@" || $@; } uninstall= while getopts du opt; do case $opt in d) DRYRUN=1 ;; u) uninstall=1 ;; *) >&2 echo "Invalid argument: $OPTARG" exit 1 ;; esac done shift $((OPTIND-1)) # Remove enabled topics if [[ $uninstall ]]; then _run rm -v "$(cd $(dirname $0) && pwd -P)"/.enabled.d/* fi # Remove dead links shopt -s nullglob links=( $HOME/.* $HOME/.*/* ) for link in ${links[@]}; do if [[ -h "$link" && ! -e "$link" ]]; then _run rm -vf "$link" fi done # vim:set ft=sh: