Allow autostow.sh to selectively ignore directories

By default autostow.sh ignores assets/ and bootstrap/ directories. This
behavior can be changed through the `AUTOSTOW_IGNORED_DIRS` environment
variable. It should contain the name of the directories to ignore,
separated by a `:`.
This commit is contained in:
Marty Oehme 2019-12-30 11:00:00 +01:00
parent df07a8e8d8
commit dba47b8e20

View file

@ -6,8 +6,43 @@
# #
# Invokes stow for every folder within this repository, and that's it. # Invokes stow for every folder within this repository, and that's it.
ignore="${AUTOSTOW_IGNORED_DIRS:-"bootstrap:assets"}"
main() {
case "$1" in
-s | --stow)
have_stow
echo "Creating dotfile symlinks ................................................."
stow_dirs
echo "Done creating symlinks ...................................................."
exit 0
;;
-d | --delete)
have_stow
echo "Removing dotfile symlinks ................................................."
unstow_dirs
echo "Done removing symlinks ...................................................."
exit 0
;;
-v | --version)
printf "System bootstrap script.\n\n©Marty Oehme\n\nVersion: 0.2\n"
;;
-h | --help | *)
usage
exit 0
;;
esac
shift
}
stow_dirs() { stow_dirs() {
for d in */; do for d in */; do
if is_ignored "$d"; then
printf "ignoring %s\n" "$d"
continue
fi
printf "stowing %s\n" "$d" printf "stowing %s\n" "$d"
stow -S -t ~ "$d" stow -S -t ~ "$d"
done done
@ -15,11 +50,27 @@ stow_dirs() {
unstow_dirs() { unstow_dirs() {
for d in */; do for d in */; do
if is_ignored "$d"; then
printf "ignoring %s\n" "$d"
continue
fi
printf "unstowing %s\n" "$d" printf "unstowing %s\n" "$d"
stow -D -t ~ "$d" stow -D -t ~ "$d"
done done
} }
is_ignored() {
IFS=":"
for ign in $ignore; do
if [ "$ign" == "$1" ] || [ "$ign/" == "$1" ]; then
return 0
fi
done
return 1
}
have_stow() { have_stow() {
if ! type stow >/dev/null 2>&1; then 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" printf "GNU stow needs to be installed for this script to function. Please install stow through your package manager.\n"
@ -46,28 +97,4 @@ usage() {
"" ""
} }
main() {
case "$1" in
-s | --stow)
have_stow
echo "Creating dotfile symlinks ................................................."
stow_dirs
echo "Done creating symlinks ...................................................."
exit 0
;;
-d | --delete)
have_stow
echo "Removing dotfile symlinks ................................................."
unstow_dirs
echo "Done removing symlinks ...................................................."
exit 0
;;
-h | --help | *)
usage
exit 0
;;
esac
shift
}
main "$@" main "$@"