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

install: use .bashrc and notify user #2039

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions clean_files.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ aliases/
docs/
hooks/
scripts/
template/

# root files
#
Expand All @@ -28,6 +29,7 @@ bash_it.sh
clean_files.txt
install.sh
lint_clean_files.sh
uninstall.sh

# completions
#
Expand Down
14 changes: 6 additions & 8 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Installation

#. Check out a clone of this repo to a location of your choice, such as
``git clone --depth=1 https://github.com/Bash-it/bash-it.git ~/.bash_it``
#. Run ``~/.bash_it/install.sh`` (it automatically backs up your ``~/.bash_profile`` or ``~/.bashrc``\ , depending on your OS)
#. Edit your modified config (\ ``~/.bash_profile`` or ``~/.bashrc``\ ) file in order to customize Bash-it.
#. Run ``~/.bash_it/install.sh`` (it automatically backs up your ``~/.bashrc``\ )
#. Edit your modified config (\ ``~/.bashrc``\ ) file in order to customize Bash-it.
#. Check out available aliases, completions, and plugins and enable the ones you want to use (see the next section for more details).

Install Options
Expand All @@ -18,7 +18,7 @@ The install script can take the following options:

* ``--interactive``\ : Asks the user which aliases, completions and plugins to enable.
* ``--silent``\ : Ask nothing and install using default settings.
* ``--no-modify-config``\ : Do not modify the existing config file (\ ``~/.bash_profile`` or ``~/.bashrc``\ ).
* ``--no-modify-config``\ : Do not modify the existing config file (\ ``~/.bashrc``\ ).
* ``--append-to-config``\ : Back up existing config file and append bash-it templates at the end.

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.
Expand All @@ -28,16 +28,14 @@ When you run without the ``--no-modify-config`` switch, the Bash-it installer au
Use the ``--no-modify-config`` switch to avoid unwanted modifications, e.g. if your Bash config file already contains the code that loads Bash-it.

**NOTE**\ : Keep in mind how Bash loads its configuration files,
``.bash_profile`` for login shells (and in macOS 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.
``.bash_profile`` for login shells and ``.bashrc`` for interactive shells, 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``\ :

.. code-block::

if [ -f ~/.bashrc ]; then
. ~/.bashrc
if [[ $- == *"i"* && -f ~/.bashrc ]]; then
source ~/.bashrc
fi

Refer to the official `Bash documentation <https://www.gnu.org/software/bash/manual/bashref.html#Bash-Startup-Files>`_ to get more info.
Expand Down
3 changes: 1 addition & 2 deletions docs/themes-list/atomic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ Automatically via terminal


#. You can install the theme automatically using the ``sed`` command from your Linux or OSX Terminal.
#. On macOS, the ~/.bash_profile is used, not the ~/.bashrc.
#. For installation on windows you should use `\ ``Git-Bash`` <https://git-for-windows.github.io/>`_ or make sure the terminal emulator you use (ej: cygwin, mintty, etc) has the ``sed`` command installed.

Command to execute For Windows and Linux:
Expand All @@ -51,7 +50,7 @@ Command to execute for macOS:
.. code-block:: bash

# Set the "atomic" theme replacing the theme you are using of bash-it
sed -i '' 's/'"$BASH_IT_THEME"'/atomic/g' ~/.bash_profile
sed -i '' 's/'"$BASH_IT_THEME"'/atomic/g' ~/.bashrc

Features
--------
Expand Down
2 changes: 1 addition & 1 deletion docs/themes-list/powerline-base.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ all powerline themes.

**IMPORTANT:** This theme requires that `a font with the Powerline symbols <https://github.com/powerline/fonts>`_ needs to be used in your terminal emulator, otherwise the prompt won't be displayed correctly, i.e. some of the additional icons and characters will be missing. Please follow your operating system's instructions to install one of the fonts from the above link and select it in your terminal emulator.

**NOTICE:** The default behavior of this theme assumes that you have sudo privileges on your workstation. If that is not the case (e.g. if you are running on a corporate network where ``sudo`` usage is tracked), you can set the flag 'export THEME_CHECK_SUDO=false' in your ``~/.bashrc`` or ``~/.bash_profile`` to disable the Powerline theme's ``sudo`` check. This will apply to all ``powerline*`` themes.
**NOTICE:** The default behavior of this theme assumes that you have sudo privileges on your workstation. If that is not the case (e.g. if you are running on a corporate network where ``sudo`` usage is tracked), you can set the flag 'export THEME_CHECK_SUDO=false' in your ``~/.bashrc`` to disable the Powerline theme's ``sudo`` check. This will apply to all ``powerline*`` themes.

Provided Information
--------------------
Expand Down
2 changes: 1 addition & 1 deletion docs/themes-list/powerline-multiline.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ To get the length of the left and right segments right, a *padding* value is use
In most cases, the default value (\ *2*\ ) works fine, but on some operating systems, this needs to be adjusted.
One example is *macOS High Sierra*\ , where the default padding causes the right segment to extend to the next line.
On macOS High Sierra, the padding value needs to be changed to *3* to make the theme look right.
This can be done by setting the ``POWERLINE_PADDING`` variable before Bash-it is loaded, e.g. in your ``~/.bash_profile`` or ``~/.bashrc`` file:
This can be done by setting the ``POWERLINE_PADDING`` variable before Bash-it is loaded, e.g. in your ``~/.bashrc`` file:

.. code-block:: bash

Expand Down
2 changes: 1 addition & 1 deletion docs/vcs_user.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Turn version control checking off to prevent slow directory navigation within la
Controlling Flags
^^^^^^^^^^^^^^^^^

Bash-it provides a flag (\ ``SCM_CHECK``\ ) within the ``~/.bash_profile`` file that turns off/on version control information checking and display within all themes.
Bash-it provides a flag (\ ``SCM_CHECK``\ ) within the ``~/.bashrc`` file that turns off/on version control information checking and display within all themes.
Version control checking is on by default unless explicitly turned off.

Set ``SCM_CHECK`` to 'false' to **turn off** version control checks for all themes:
Expand Down
143 changes: 67 additions & 76 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# bash-it installer

# Show how to use this installer
function _bash-it_show_usage() {
function _bash-it-install-help() {
echo -e "\n$0 : Install bash-it"
echo -e "Usage:\n$0 [arguments] \n"
echo "Arguments:"
Expand All @@ -15,77 +15,63 @@ function _bash-it_show_usage() {
exit 0
}

# enable a thing
function _bash-it_load_one() {
file_type=$1
file_to_enable=$2
mkdir -p "$BASH_IT/${file_type}/enabled"

dest="${BASH_IT}/${file_type}/enabled/${file_to_enable}"
if [ ! -e "${dest}" ]; then
ln -sf "../available/${file_to_enable}" "${dest}"
else
echo "File ${dest} exists, skipping"
fi
}

# Interactively enable several things
function _bash-it_load_some() {
function _bash-it-install-enable() {
local file_type single_type enable_func file_name just_the_name RESP
file_type=$1
single_type=$(echo "$file_type" | sed -e "s/aliases$/alias/g" | sed -e "s/plugins$/plugin/g")
enable_func="_enable-$single_type"
[ -d "$BASH_IT/$file_type/enabled" ] || mkdir "$BASH_IT/$file_type/enabled"
for path in "$BASH_IT/${file_type}/available/"[^_]*; do
file_name=$(basename "$path")
for path in "${BASH_IT?}/${file_type}/available/"[^_]*; do
file_name="${path##*/}"
while true; do
just_the_name="${file_name%%.*}"
just_the_name="${file_name%".${file_type}.bash"}"
read -r -e -n 1 -p "Would you like to enable the $just_the_name $file_type? [y/N] " RESP
case $RESP in
[yY])
$enable_func "$just_the_name"
"$enable_func" "$just_the_name"
break
;;
[nN] | "")
break
;;
*)
echo -e "\033[91mPlease choose y or n.\033[m"
echo -e "${echo_orange:-}Please choose y or n.${echo_normal:-}"
;;
esac
done
done
}

# Back up existing profile
function _bash-it_backup() {
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"
function _bash-it-install-backup-config() {
test -w "${HOME?}/${CONFIG_FILE?}" \
&& cp -aL "${HOME?}/${CONFIG_FILE?}" "${HOME?}/${CONFIG_FILE?}.bak" \
&& echo -e "${echo_green:-}Your original ${CONFIG_FILE?} has been backed up to ${CONFIG_FILE?}.bak${echo_normal:-}"
}

# Back up existing profile and create new one for bash-it
function _bash-it_backup_new() {
_bash-it_backup
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"
function _bash-it-install-backup-new() {
_bash-it-install-backup-config
sed "s|{{BASH_IT}}|${BASH_IT?}|" "${BASH_IT?}/template/bashrc.template.bash" > "${HOME?}/${CONFIG_FILE?}"
echo -e "${echo_green:-}Copied the template ${CONFIG_FILE?} into ~/${CONFIG_FILE?}, edit this file to customize bash-it${echo_normal:-}"
}

# Back up existing profile and append bash-it templates at the end
function _bash-it_backup_append() {
_bash-it_backup
(sed "s|{{BASH_IT}}|$BASH_IT|" "$BASH_IT/template/bash_profile.template.bash" | tail -n +2) >> "$HOME/$CONFIG_FILE"
echo -e "\033[0;32mBash-it template has been added to your $CONFIG_FILE\033[0m"
function _bash-it-install-backup-append() {
_bash-it-install-backup-config
(sed "s|{{BASH_IT}}|${BASH_IT?}|" "${BASH_IT?}/template/bashrc.template.bash" | tail -n +2) >> "${HOME?}/${CONFIG_FILE?}"
echo -e "${echo_green:-}Bash-it template has been added to your ${CONFIG_FILE?}${echo_normal:-}"
}

function _bash-it_check_for_backup() {
if ! [[ -e "$HOME/$BACKUP_FILE" ]]; then
function _bash-it-install-backup-check() {
if ! [[ -e "${HOME?}/$BACKUP_FILE" ]]; then
return
fi
echo -e "\033[0;33mBackup file already exists. Make sure to backup your .bashrc before running this installation.\033[0m" >&2
echo -e "${echo_yellow:-}Backup file already exists. Make sure to backup your .bashrc before running this installation.${echo_normal:-}" >&2

if [[ -z "${overwrite_backup}" ]]; then
while [[ -z "${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
case $RESP in
[yY])
overwrite_backup=true
Expand All @@ -95,28 +81,28 @@ function _bash-it_check_for_backup() {
break
;;
*)
echo -e "\033[91mPlease choose y or n.\033[m"
echo -e "${echo_orange:-}Please choose y or n.${echo_normal:-}"
;;
esac
done
fi
if [[ -z "${overwrite_backup}" ]]; then
echo -e "\033[91mInstallation aborted. Please come back soon!\033[m"
echo -e "${echo_orange:-}Installation aborted. Please come back soon!${echo_normal:-}"
if [[ -n "${silent}" ]]; then
echo -e "\033[91mUse \"-f\" flag to force overwrite of backup.\033[m"
echo -e "${echo_orange:-}Use \"-f\" flag to force overwrite of backup.${echo_normal:-}"
fi
exit 1
else
echo -e "\033[0;32mOverwriting backup...\033[m"
echo -e "${echo_green:-}Overwriting backup...${echo_normal:-}"
fi
}

function _bash-it_modify_config_files() {
_bash-it_check_for_backup
function _bash-it-install-modify-config() {
_bash-it-install-backup-check

if [[ -z "${silent}" ]]; then
while [[ -z "${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
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
Expand All @@ -126,17 +112,28 @@ function _bash-it_modify_config_files() {
break
;;
*)
echo -e "\033[91mPlease choose y or n.\033[m"
echo -e "${echo_orange:-}Please choose y or n.${echo_normal:-}"
;;
esac
done
fi
if [[ -n "${append_to_config}" ]]; then
if [[ -n "${append_to_config:-}" ]]; then
# backup/append
_bash-it_backup_append
_bash-it-install-backup-append
else
# backup/new by default
_bash-it_backup_new
_bash-it-install-backup-new
fi
_bash-it-install-modify-profile
}

function _bash-it-install-modify-profile() {
local choice profile_string=$'if [[ $- == *i* && -s ~/.bashrc ]]; then\n\tsource ~/.bashrc\nfi'
if [[ ! -f ~/.bash_profile ]]; then
printf '%s\n' "${profile_string}" > ~/.bash_profile
else
printf "${echo_yellow:-}%s${echo_normal:-}" "You may need to update your ~/.bash_profile (or ~/.profile) to source your ~/.bashrc:"
printf '%s\n' "${profile_string}"
fi
}

Expand All @@ -157,7 +154,7 @@ OPTIND=1
while getopts "hsinaf" opt; do
case "$opt" in
"h")
_bash-it_show_usage
_bash-it-install-help
exit 0
;;
"s") silent=true ;;
Expand All @@ -166,7 +163,7 @@ while getopts "hsinaf" opt; do
"a") append_to_config=true ;;
"f") overwrite_backup=true ;;
"?")
_bash-it_show_usage >&2
_bash-it-install-help >&2
exit 1
;;
esac
Expand All @@ -175,59 +172,53 @@ done
shift $((OPTIND - 1))

if [[ -n "${silent}" && -n "${interactive}" ]]; then
echo -e "\033[91mOptions --silent and --interactive are mutually exclusive. Please choose one or the other.\033[m"
echo -e "${echo_orange:-}Options --silent and --interactive are mutually exclusive. Please choose one or the other.${echo_normal:-}"
exit 1
fi

if [[ -n "${no_modify_config}" && -n "${append_to_config}" ]]; then
echo -e "\033[91mOptions --no-modify-config and --append-to-config are mutually exclusive. Please choose one or the other.\033[m"
echo -e "${echo_orange:-}Options --no-modify-config and --append-to-config are mutually exclusive. Please choose one or the other.${echo_normal:-}"
exit 1
fi

BASH_IT="$(cd "${BASH_SOURCE%/*}" && pwd)"

case $OSTYPE in
darwin*)
CONFIG_FILE=.bash_profile
;;
*)
CONFIG_FILE=.bashrc
;;
esac
CONFIG_FILE=".bashrc"

BACKUP_FILE=$CONFIG_FILE.bak
BACKUP_FILE="${CONFIG_FILE?}.bak"
echo "Installing bash-it"
if [[ -z "${no_modify_config}" ]]; then
_bash-it_modify_config_files
_bash-it-install-modify-config
fi

# Disable auto-reload in case its enabled
export BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE=''
# Load dependencies for enabling components
# shellcheck disable=SC1090
source "${BASH_IT}"/vendor/github.com/erichs/composure/composure.sh
# shellcheck source=./lib/utilities.bash
source "$BASH_IT/lib/utilities.bash"
# shellcheck source=./lib/log.bash
source "${BASH_IT}/lib/log.bash"
# shellcheck source-path=SCRIPTPATH/vendor/github.com/erichs/composure
source "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh"
cite _about _param _example _group _author _version
# shellcheck source=./lib/helpers.bash
source "$BASH_IT/lib/helpers.bash"
# shellcheck source-path=SCRIPTDIR/lib
source "${BASH_IT}/lib/log.bash"
# shellcheck source-path=SCRIPTDIR/lib
source "${BASH_IT?}/lib/utilities.bash"
# shellcheck source-path=SCRIPTDIR/lib
source "${BASH_IT?}/lib/helpers.bash"
# shellcheck source-path=SCRIPTDIR/lib
source "${BASH_IT?}/lib/colors.bash"

if [[ -n $interactive && -z "${silent}" ]]; then
for type in "aliases" "plugins" "completion"; do
echo -e "\033[0;32mEnabling ${type}\033[0m"
_bash-it_load_some "$type"
echo -e "${echo_green:-}Enabling ${type}${echo_normal:-}"
_bash-it-install-enable "$type"
done
else
echo ""
_bash-it-profile-load "default"
fi

echo ""
echo -e "\033[0;32mInstallation finished successfully! Enjoy bash-it!\033[0m"
# shellcheck disable=SC2086
echo -e "\033[0;32mTo start using it, open a new tab or 'source "~/$CONFIG_FILE"'.\033[0m"
echo -e "${echo_green:-}Installation finished successfully! Enjoy bash-it!${echo_normal:-}"
echo -e "${echo_green:-}To start using it, open a new tab or 'source ~/${CONFIG_FILE?}'.${echo_normal:-}"
echo ""
echo "To show the available aliases/completions/plugins, type one of the following:"
echo " bash-it show aliases"
Expand Down
Loading