helm/clean
2016-11-15 02:20:36 +01:00

38 lines
712 B
Bash
Executable file

#!/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))
shopt -s nullglob
links=( $HOME/.* $HOME/.*/* )
for link in ${links[@]}; do
if [[ -h "$link" && ! -e "$link" ]]; then
_run rm -vf "$link"
fi
done
if [[ $uninstall ]]; then
_run rm -v "$(cd $(dirname $0) && pwd -P)"/.enabled.d/*
fi
# vim:set ft=sh: