dotfiles/bootstrap/.config/bootstrap/autostow.sh

74 lines
1.6 KiB
Bash
Raw Normal View History

#!/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 ................................................."
stow_dirs
2019-12-30 09:20:17 +00:00
echo "Done creating symlinks ...................................................."
exit 0
;;
-d | --delete)
have_stow
2019-12-30 09:20:17 +00:00
echo "Removing dotfile symlinks ................................................."
unstow_dirs
2019-12-30 09:20:17 +00:00
echo "Done removing symlinks ...................................................."
exit 0
;;
-h | --help | *)
usage
exit 0
;;
esac
shift
}
main "$@"