2016-11-14 17:20:36 -08:00
|
|
|
#!/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))
|
|
|
|
|
2016-12-23 15:21:40 -08:00
|
|
|
# Remove enabled topics
|
|
|
|
if [[ $uninstall ]]; then
|
|
|
|
_run rm -v "$(cd $(dirname $0) && pwd -P)"/.enabled.d/*
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Remove dead links
|
2016-11-14 17:20:36 -08:00
|
|
|
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:
|