install: Move modify config check into separate function

This helps us make the logic easier to read, and remove unneeded
confusion.
pull/1830/head
Noah Gorny 2021-02-05 23:25:21 +02:00
parent 71116f785f
commit ef10bcd151
1 changed files with 48 additions and 42 deletions

View File

@ -76,6 +76,52 @@ function backup_append() {
echo -e "\033[0;32mBash-it template has been added to your $CONFIG_FILE\033[0m" echo -e "\033[0;32mBash-it template has been added to your $CONFIG_FILE\033[0m"
} }
function modify_config_files() {
if ! [[ $silent ]]; then
if [ -e "$HOME/$BACKUP_FILE" ]; then
echo -e "\033[0;33mBackup file already exists. Make sure to backup your .bashrc before running this installation.\033[0m" >&2
while ! [[ $silent ]]; do
read -e -n 1 -r -p "Would you like to overwrite the existing backup? This will delete your existing backup file ($HOME/$BACKUP_FILE) [y/N] " RESP
case $RESP in
[yY])
break
;;
[nN] | "")
echo -e "\033[91mInstallation aborted. Please come back soon!\033[m"
exit 1
;;
*)
echo -e "\033[91mPlease choose y or n.\033[m"
;;
esac
done
fi
while ! [[ $append_to_config ]]; do
read -e -n 1 -r -p "Would you like to keep your $CONFIG_FILE and append bash-it templates at the end? [y/N] " choice
case $choice in
[yY])
append_to_config=true
break
;;
[nN] | "")
break
;;
*)
echo -e "\033[91mPlease choose y or n.\033[m"
;;
esac
done
fi
if [[ $append_to_config ]]; then
# backup/append
backup_append
else
# backup/new by default
backup_new
fi
}
for param in "$@"; do for param in "$@"; do
shift shift
case "$param" in case "$param" in
@ -130,48 +176,8 @@ esac
BACKUP_FILE=$CONFIG_FILE.bak BACKUP_FILE=$CONFIG_FILE.bak
echo "Installing bash-it" echo "Installing bash-it"
if ! [[ $silent ]] && ! [[ $no_modify_config ]]; then if ! [[ $no_modify_config ]]; then
if [ -e "$HOME/$BACKUP_FILE" ]; then modify_config_files
echo -e "\033[0;33mBackup file already exists. Make sure to backup your .bashrc before running this installation.\033[0m" >&2
while ! [ $silent ]; do
read -e -n 1 -r -p "Would you like to overwrite the existing backup? This will delete your existing backup file ($HOME/$BACKUP_FILE) [y/N] " RESP
case $RESP in
[yY])
break
;;
[nN] | "")
echo -e "\033[91mInstallation aborted. Please come back soon!\033[m"
exit 1
;;
*)
echo -e "\033[91mPlease choose y or n.\033[m"
;;
esac
done
fi
while ! [ $append_to_config ]; do
read -e -n 1 -r -p "Would you like to keep your $CONFIG_FILE and append bash-it templates at the end? [y/N] " choice
case $choice in
[yY])
backup_append
break
;;
[nN] | "")
backup_new
break
;;
*)
echo -e "\033[91mPlease choose y or n.\033[m"
;;
esac
done
elif [[ $append_to_config ]]; then
# backup/append
backup_append
elif [[ $silent ]] && ! [[ $no_modify_config ]]; then
# backup/new by default
backup_new
fi fi
# Disable auto-reload in case its enabled # Disable auto-reload in case its enabled