From 4dfb9767eeeb92cd59ee42aeb98e8625abc815d8 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Thu, 30 Jan 2020 12:50:37 +0100 Subject: [PATCH] Add dryrun capability to autostow.sh Invoking a dry-run with `autostow.sh -n` will simply print out the directories it would operate on, and those it would ignore and exit. Useful for debugging, not much more. --- bootstrap/autostow.sh | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/bootstrap/autostow.sh b/bootstrap/autostow.sh index 4f3f866..cbe0482 100755 --- a/bootstrap/autostow.sh +++ b/bootstrap/autostow.sh @@ -24,6 +24,13 @@ main() { echo "Done removing symlinks ...................................................." exit 0 ;; + -n | --dry-run) + have_stow + echo "Printing processed directories ............................................" + dryrun + echo "Done printing directories ................................................." + exit 0 + ;; -v | --version) printf "System bootstrap script.\n\n©Marty Oehme\n\nVersion: 0.2\n" ;; @@ -61,6 +68,18 @@ unstow_dirs() { done } +dryrun() { + for d in */; do + + if is_ignored "$d"; then + printf "ignoring %s\n" "$d" + continue + fi + + printf "processing %s\n" "$d" + done +} + is_ignored() { IFS=":" for ign in $ignore; do @@ -84,13 +103,17 @@ usage() { " 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" \ + " Usage: stow.sh -dhsn" \ "" \ " Options:" \ "" \ - " -h Print out this help." \ + " -h | --help Print out this help." \ "" \ - " -s Install dotfiles, by symlinking any directory found next to stow.sh using GNU stow." \ + " -s | --stow Install dotfiles, by symlinking any directory found next to stow.sh using GNU stow." \ + "" \ + " -d | --delete Remove dotfiles, by unlinking any directory found next to stow.sh using GNU stow." \ + "" \ + " -n | --dry-run Do not invoke any operation but print out directories affected, simulating a dry-run." \ "" \ " -d Remove dotfiles, by unlinking any directory found next to stow.sh using GNU stow." \ "" \