-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
simplify install #1830
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ef10bcd
install: Move modify config check into separate function
9e37f0d
install: Move backup check into a separate function
af17501
install: Add --overwrite-backup flag
3e7adde
install: Move to double brackets in check_for-backup check
5c19257
install: Add bash-it prefix to all functions
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
} | ||
|
||
|
@@ -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() { | ||
if ! [ -e "$HOME/$BACKUP_FILE" ]; then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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