Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplify install #1830

Merged
merged 5 commits into from
Feb 6, 2021
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 69 additions & 43 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function show_usage() {
echo "--interactive (-i): Interactively choose plugins"
echo "--no-modify-config (-n): Do not modify existing config file"
echo "--append-to-config (-a): Keep existing config file and append bash-it templates at the end"
echo "--overwrite-backup (-f): Overwrite existing backup"
exit 0
}

Expand Down Expand Up @@ -76,6 +77,69 @@ function backup_append() {
echo -e "\033[0;32mBash-it template has been added to your $CONFIG_FILE\033[0m"
}

function check_for_backup() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not going to road block since this in the install script, but it'd be nice to start making all functions be prefixed with _bash-it or something consistent and namespaced.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added this prefix to all functions in install.sh

if ! [ -e "$HOME/$BACKUP_FILE" ]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double bracket test are technically safer. if we're writing or transposing new things, I'd like to push to switch

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return
fi
echo -e "\033[0;33mBackup file already exists. Make sure to backup your .bashrc before running this installation.\033[0m" >&2

if ! [[ $overwrite_backup ]]; then
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])
overwrite_backup=true
break
;;
[nN] | "")
break
;;
*)
echo -e "\033[91mPlease choose y or n.\033[m"
;;
esac
done
fi
if ! [[ $overwrite_backup ]]; then
echo -e "\033[91mInstallation aborted. Please come back soon!\033[m"
if [[ $silent ]]; then
echo -e "\033[91mUse \"-f\" flag to force overwrite of backup.\033[m"
fi
exit 1
else
echo -e "\033[0;32mOverwriting backup...\033[m"
fi
}

function modify_config_files() {
check_for_backup

if ! [[ $silent ]]; then
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
shift
case "$param" in
Expand All @@ -84,12 +148,13 @@ for param in "$@"; do
"--interactive") set -- "$@" "-i" ;;
"--no-modify-config") set -- "$@" "-n" ;;
"--append-to-config") set -- "$@" "-a" ;;
"--overwrite-backup") set -- "$@" "-f" ;;
*) set -- "$@" "$param" ;;
esac
done

OPTIND=1
while getopts "hsina" opt; do
while getopts "hsinaf" opt; do
case "$opt" in
"h")
show_usage
Expand All @@ -99,6 +164,7 @@ while getopts "hsina" opt; do
"i") interactive=true ;;
"n") no_modify_config=true ;;
"a") append_to_config=true ;;
"f") overwrite_backup=true ;;
"?")
show_usage >&2
exit 1
Expand Down Expand Up @@ -130,48 +196,8 @@ esac

BACKUP_FILE=$CONFIG_FILE.bak
echo "Installing bash-it"
if ! [[ $silent ]] && ! [[ $no_modify_config ]]; 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])
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
if ! [[ $no_modify_config ]]; then
modify_config_files
fi

# Disable auto-reload in case its enabled
Expand Down