Add autostow.sh automatic stowing utility

Will only reside in repository folder. Symlinks anything in a
subdirectory into the corresponding place in home directory.
This commit is contained in:
Marty Oehme 2019-12-30 09:13:23 +01:00
parent 34779454be
commit ed040d9caa
2 changed files with 73 additions and 30 deletions

73
autostow.sh Executable file
View file

@ -0,0 +1,73 @@
#!/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 "$@"

30
stow.sh
View file

@ -1,30 +0,0 @@
#!/usr/bin/env bash
#
# Stow automatic symlinking script
#
# Invokes stow for every folder within this repository, and that's it.
# to_stow=$(ls -l --time-style="long-iso" . | grep -E '^d' | awk '{print $8}')
stow_dirs() {
for d in */; do
printf "stowing %s\n" "$d"
stow "$d"
done
}
have_stow() {
type stow >/dev/null 2>&1 || printf "GNU stow needs to be installed for this script to function. Please install stow through your package manager.\n"
exit 1
}
while [ "$1" != "" ]; do
case "$1" in
-s | --stow)
have_stow
stow_dirs
exit
;;
esac
shift
done