2019-12-30 08:13:23 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
|
|
|
# autostow.sh
|
|
|
|
#
|
|
|
|
# Stow automatic symlinking script
|
|
|
|
#
|
|
|
|
# Invokes stow for every folder within this repository, and that's it.
|
|
|
|
|
|
|
|
stow_dirs() {
|
|
|
|
for d in */; do
|
|
|
|
printf "stowing %s\n" "$d"
|
|
|
|
stow -S -t ~ "$d"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
unstow_dirs() {
|
|
|
|
for d in */; do
|
|
|
|
printf "unstowing %s\n" "$d"
|
|
|
|
stow -D -t ~ "$d"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
have_stow() {
|
|
|
|
if ! type stow >/dev/null 2>&1; then
|
|
|
|
printf "GNU stow needs to be installed for this script to function. Please install stow through your package manager.\n"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
usage() {
|
|
|
|
printf "%s\n" \
|
|
|
|
"" \
|
|
|
|
" autostow.sh - Automatically stow your dotfiles." \
|
|
|
|
" Uses GNU stow to set up automatic links to any dotfiles in subdirectories of this directory." \
|
|
|
|
"" \
|
|
|
|
" Usage: stow.sh -dhs" \
|
|
|
|
"" \
|
|
|
|
" Options:" \
|
|
|
|
"" \
|
|
|
|
" -h Print out this help." \
|
|
|
|
"" \
|
|
|
|
" -s Install dotfiles, by symlinking any directory found next to stow.sh using GNU stow." \
|
|
|
|
"" \
|
|
|
|
" -d Remove dotfiles, by unlinking any directory found next to stow.sh using GNU stow." \
|
|
|
|
"" \
|
|
|
|
""
|
|
|
|
}
|
|
|
|
|
|
|
|
main() {
|
|
|
|
case "$1" in
|
|
|
|
-s | --stow)
|
|
|
|
have_stow
|
2019-12-30 09:20:17 +00:00
|
|
|
echo "Creating dotfile symlinks ................................................."
|
2019-12-30 08:13:23 +00:00
|
|
|
stow_dirs
|
2019-12-30 09:20:17 +00:00
|
|
|
echo "Done creating symlinks ...................................................."
|
2019-12-30 08:13:23 +00:00
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
-d | --delete)
|
|
|
|
have_stow
|
2019-12-30 09:20:17 +00:00
|
|
|
echo "Removing dotfile symlinks ................................................."
|
2019-12-30 08:13:23 +00:00
|
|
|
unstow_dirs
|
2019-12-30 09:20:17 +00:00
|
|
|
echo "Done removing symlinks ...................................................."
|
2019-12-30 08:13:23 +00:00
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
-h | --help | *)
|
|
|
|
usage
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
}
|
|
|
|
|
|
|
|
main "$@"
|