Merge pull request #810 from knorth55/install-modify-config

[install.sh] add flag not to modify exist config file during installation
pull/834/head
Nils Winkler 2016-11-07 08:27:14 +01:00 committed by GitHub
commit 71b7f95661
2 changed files with 44 additions and 37 deletions

View File

@ -20,8 +20,12 @@ The install script can take the following options:
* `--interactive`: Asks the user which aliases, completions and plugins to enable. * `--interactive`: Asks the user which aliases, completions and plugins to enable.
* `--no-modify-config`: Do not modify config file (~/.bash_profile or ~/.bashrc).
When run without the `--interactive` switch, Bash-it only enables a sane default set of functionality to keep your shell clean and to avoid issues with missing dependencies. Feel free to enable the tools you want to use after the installation. When run without the `--interactive` switch, Bash-it only enables a sane default set of functionality to keep your shell clean and to avoid issues with missing dependencies. Feel free to enable the tools you want to use after the installation.
When you run without the `--no-modify-config` switch, Bash-it installation automatically modify your existing config file.
**NOTE**: Keep in mind how Bash load its configuration files, `.bash_profile` for login shells (and in Mac OS X in terminal emulators like [Terminal.app](http://www.apple.com/osx/apps/) or [iTerm2](https://www.iterm2.com/)) and `.bashrc` for interactive shells (default mode in most of the GNU/Linux terminal emulators), to ensure that Bash-it is loaded correctly. A good "practice" is sourcing `.bashrc` into `.bash_profile` to keep things working in all the scenarios, to achieve this, you can add this snippet in your `.bash_profile`: **NOTE**: Keep in mind how Bash load its configuration files, `.bash_profile` for login shells (and in Mac OS X in terminal emulators like [Terminal.app](http://www.apple.com/osx/apps/) or [iTerm2](https://www.iterm2.com/)) and `.bashrc` for interactive shells (default mode in most of the GNU/Linux terminal emulators), to ensure that Bash-it is loaded correctly. A good "practice" is sourcing `.bashrc` into `.bash_profile` to keep things working in all the scenarios, to achieve this, you can add this snippet in your `.bash_profile`:
``` ```

View File

@ -9,6 +9,7 @@ function show_usage() {
echo "--help (-h): Display this help message" echo "--help (-h): Display this help message"
echo "--silent (-s): Install default settings without prompting for input"; echo "--silent (-s): Install default settings without prompting for input";
echo "--interactive (-i): Interactively choose plugins" echo "--interactive (-i): Interactively choose plugins"
echo "--no-modify-config (-n): Do not modify existing config file"
exit 0; exit 0;
} }
@ -67,17 +68,19 @@ for param in "$@"; do
"--help") set -- "$@" "-h" ;; "--help") set -- "$@" "-h" ;;
"--silent") set -- "$@" "-s" ;; "--silent") set -- "$@" "-s" ;;
"--interactive") set -- "$@" "-i" ;; "--interactive") set -- "$@" "-i" ;;
"--no-modify-config") set -- "$@" "-n" ;;
*) set -- "$@" "$param" *) set -- "$@" "$param"
esac esac
done done
OPTIND=1 OPTIND=1
while getopts "hsi" opt while getopts "hsin" opt
do do
case "$opt" in case "$opt" in
"h") show_usage; exit 0 ;; "h") show_usage; exit 0 ;;
"s") silent=true ;; "s") silent=true ;;
"i") interactive=true ;; "i") interactive=true ;;
"n") no_modify_config=true ;;
"?") show_usage >&2; exit 1 ;; "?") show_usage >&2; exit 1 ;;
esac esac
done done
@ -101,7 +104,8 @@ esac
BACKUP_FILE=$CONFIG_FILE.bak BACKUP_FILE=$CONFIG_FILE.bak
echo "Installing bash-it" echo "Installing bash-it"
if [ -e "$HOME/$BACKUP_FILE" ]; then 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 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
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 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
@ -118,9 +122,9 @@ if [ -e "$HOME/$BACKUP_FILE" ]; then
;; ;;
esac esac
done done
fi fi
while ! [ $silent ]; do while ! [ $silent ]; 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])
@ -140,9 +144,8 @@ while ! [ $silent ]; do
echo -e "\033[91mPlease choose y or n.\033[m" echo -e "\033[91mPlease choose y or n.\033[m"
;; ;;
esac esac
done done
elif [[ $silent ]] && ! [[ $no_modify_config ]]; then
if [ $silent ]; then
# backup/new by default # backup/new by default
backup_new backup_new
fi fi