Colorized error, relocated installing message, created backup_new func, reformatted do

pull/725/head
ravenhall 2016-05-31 14:14:12 -05:00
parent 11311b17f6
commit c6c21abb0e
1 changed files with 13 additions and 16 deletions

View File

@ -10,8 +10,6 @@ show_usage() {
exit 0; exit 0;
} }
echo "Installing bash-it"
for param in "$@"; do for param in "$@"; do
shift shift
case "$param" in case "$param" in
@ -35,7 +33,7 @@ done
shift $(expr $OPTIND - 1) shift $(expr $OPTIND - 1)
if [[ $silent ]] && [[ $interactive ]]; then if [[ $silent ]] && [[ $interactive ]]; then
echo "Options --silent and --interactive are mutually exclusive. Please choose one or the other." echo "\033[91mOptions --silent and --interactive are mutually exclusive. Please choose one or the other.\033[m"
exit 1; exit 1;
fi fi
@ -51,7 +49,7 @@ case $OSTYPE in
esac esac
BACKUP_FILE=$CONFIG_FILE.bak BACKUP_FILE=$CONFIG_FILE.bak
echo "Installing bash-it"
if [ -e "$HOME/$BACKUP_FILE" ]; 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 echo -e "\033[0;33mBackup file already exists. Make sure to backup your .bashrc before running this installation.\033[0m" >&2
while ! [ $silent ]; do while ! [ $silent ]; do
@ -71,8 +69,7 @@ if [ -e "$HOME/$BACKUP_FILE" ]; then
done done
fi fi
while ! [ $silent ] while ! [ $silent ]; do
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 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 case $choice in
[yY]) [yY])
@ -85,10 +82,7 @@ do
break break
;; ;;
[nN]|"") [nN]|"")
test -w "$HOME/$CONFIG_FILE" && backup_new
cp -aL "$HOME/$CONFIG_FILE" "$HOME/$CONFIG_FILE.bak" &&
echo -e "\033[0;32mYour original $CONFIG_FILE has been backed up to $CONFIG_FILE.bak\033[0m"
sed "s|{{BASH_IT}}|$BASH_IT|" "$BASH_IT/template/bash_profile.template.bash" > "$HOME/$CONFIG_FILE"
break break
;; ;;
*) *)
@ -99,14 +93,9 @@ done
if [ $silent ]; then if [ $silent ]; then
# backup/new by default # backup/new by default
test -w "$HOME/$CONFIG_FILE" && backup_new
cp -aL "$HOME/$CONFIG_FILE" "$HOME/$CONFIG_FILE.bak" &&
echo -e "\033[0;32mYour original $CONFIG_FILE has been backed up to $CONFIG_FILE.bak\033[0m"
sed "s|{{BASH_IT}}|$BASH_IT|" "$BASH_IT/template/bash_profile.template.bash" > "$HOME/$CONFIG_FILE"
fi fi
echo -e "\033[0;32mCopied the template $CONFIG_FILE into ~/$CONFIG_FILE, edit this file to customize bash-it\033[0m"
function load_one() { function load_one() {
file_type=$1 file_type=$1
file_to_enable=$2 file_to_enable=$2
@ -145,6 +134,14 @@ function load_some() {
done done
} }
function backup_new() {
test -w "$HOME/$CONFIG_FILE" &&
cp -aL "$HOME/$CONFIG_FILE" "$HOME/$CONFIG_FILE.bak" &&
echo -e "\033[0;32mYour original $CONFIG_FILE has been backed up to $CONFIG_FILE.bak\033[0m"
sed "s|{{BASH_IT}}|$BASH_IT|" "$BASH_IT/template/bash_profile.template.bash" > "$HOME/$CONFIG_FILE"
echo -e "\033[0;32mCopied the template $CONFIG_FILE into ~/$CONFIG_FILE, edit this file to customize bash-it\033[0m"
}
if [[ $interactive ]] && ! [[ $silent ]] ; if [[ $interactive ]] && ! [[ $silent ]] ;
then then
for type in "aliases" "plugins" "completion" for type in "aliases" "plugins" "completion"