dotfiles/autostow.sh
Marty Oehme ed040d9caa Add autostow.sh automatic stowing utility
Will only reside in repository folder. Symlinks anything in a
subdirectory into the corresponding place in home directory.
2019-12-30 09:13:23 +01:00

73 lines
1.6 KiB
Bash
Executable file

#!/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
printf "Creating dotfile symlinks ........................\n"
stow_dirs
printf "Done creating symlinks ...........................\n"
exit 0
;;
-d | --delete)
have_stow
printf "Removing dotfile symlinks ........................\n"
unstow_dirs
printf "Done removing symlinks ...........................\n"
exit 0
;;
-h | --help | *)
usage
exit 0
;;
esac
shift
}
main "$@"