From d89c157503ae11e7effe1e9efcfeed654c96f69f Mon Sep 17 00:00:00 2001 From: Oscar Wallberg Date: Sat, 3 Aug 2024 04:01:41 +0200 Subject: [PATCH] feat(setup): add force flag --- setup.sh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/setup.sh b/setup.sh index 4826c04..abd534c 100755 --- a/setup.sh +++ b/setup.sh @@ -12,6 +12,7 @@ SOURCE_DIR="$SCRIPT_DIR" DEST_DIR="$HOME" PRINT_HELP=false +FORCE=false REMOVE_EXISTING=false IGNORE_EXISTING=false ERROR=false @@ -131,8 +132,10 @@ create_symlink() { fi if test -L "$dst"; then - if $IGNORE_EXISTING; then + if $FORCE; then remove_symlink "$2" + elif $IGNORE_EXISTING; then + return else error "path already exists:" error "$dst" @@ -173,9 +176,10 @@ print_help() { echo "Usage: $SCRIPT_NAME [...]" echo "" echo "Options:" - echo " -h, --help Print this help message" - echo " -i, --ignore-existing Ignore existing symlinks" - echo " -r, --remove-existing Remove any existing symlinks" + echo " -h, --help Print this help message" + echo " -f, --force Overwrite any existing links" + echo " -i, --ignore-existing Ignore existing symlinks" + echo " -r, --remove-existing Remove any existing symlinks" } while [ $# -gt 0 ]; do @@ -184,6 +188,10 @@ while [ $# -gt 0 ]; do PRINT_HELP=true shift ;; + -f|--force) + FORCE=true + shift + ;; -r|--remove-existing) REMOVE_EXISTING=true shift