From d0615d3c88f4520d9d97602c2fa5e3fb900b54f8 Mon Sep 17 00:00:00 2001 From: Tristan Williams Date: Sun, 13 Oct 2024 12:55:01 -0400 Subject: Give user options for directories similar to files --- new-user-setup.sh | 47 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/new-user-setup.sh b/new-user-setup.sh index 7b8dbe1..072404b 100755 --- a/new-user-setup.sh +++ b/new-user-setup.sh @@ -47,7 +47,6 @@ echo "### Starting dotfiles.core installation... ###" ######################################################################## ## Put files into place ######################################################################## - # File placement function place_file () { file=$1 @@ -98,12 +97,48 @@ place_file () { # Directory placement function place_directory () { - directory=$1 - if [[ -d $directory ]]; then - echo -e "${YELLOW}Skipped: Dir : ${directory}${ENDCOLOR}" + target=$1 + if [[ -d $target ]]; then + echo -e \ + "${WARN}WARNING: Dir : ${target} already exists!" \ + "[A]bort, [D]elete, [R]eplace, [S]kip: ${ENDCOLOR}" + invalid_selection=0 + while + # The following echo fixes read's annoying newline that + # messes up my nice script formatting. It sends cursor back + # to the "target already exists" line. + # \033[1A moves up to previous line. + # \033[1000C moves to the last column in the line up to 1000. + echo -en "\033[1A\033[1000C" + read -n1 selection + case $selection in + "a"|"A") + echo "INFO : Abort!" + exit 0;; + "d"|"D") + rm -rf $target + echo -e "${YELLOW}Removed: Dir : ${target}${ENDCOLOR}" + mkdir -p $target + echo -e "${GREEN}Created: Dir : ${target}${ENDCOLOR}" + return 0;; + "r"|"R") + mv -f $target $target.bak + echo -e "${YELLOW}Moved : Dir : ${target} to ${target}.bak${ENDCOLOR}" + mkdir -p $target + echo -e "${GREEN}Created: Dir : ${target}${ENDCOLOR}" + return 0;; + "s"|"S") + echo -e "${YELLOW}Skipped: Dir : ${target}${ENDCOLOR}" + return 0;; + *) + echo -e "${WARN}ERROR : Invalid selection, try again...${ENDCOLOR}" + invalid_selection=1;; + esac + [[ $invalid_selection==1 ]] + do true; done else - mkdir -p $directory - echo -e "${GREEN}Created: Dir : ${directory}${ENDCOLOR}" + mkdir -p $target + echo -e "${GREEN}Created: Dir : ${target}${ENDCOLOR}" fi } -- cgit v1.2.3