diff --git a/autostow.sh b/autostow.sh new file mode 100755 index 0000000..c5debc3 --- /dev/null +++ b/autostow.sh @@ -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 "$@" diff --git a/stow.sh b/stow.sh deleted file mode 100755 index fe352a0..0000000 --- a/stow.sh +++ /dev/null @@ -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