From e888ddf9536b50690560144ef0bd25e5991db5f4 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 4 Mar 2022 12:16:38 -0800 Subject: [PATCH 01/12] install: use `.bashrc` and notify user The logic to guess whether to use `.bash_profile` or `.bashrc` was buggy and wrong. Just use `.bashrc` and either automatically fill in a `.bash_profile`, or notify the user that they need to edit their `.bash_profile`. --- install.sh | 27 +++++++++++++-------------- test/install/install.bats | 10 +--------- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/install.sh b/install.sh index 2bb78a3f..927a260b 100755 --- a/install.sh +++ b/install.sh @@ -72,8 +72,14 @@ function _bash-it_backup_new() { # Back up existing profile and append bash-it templates at the end function _bash-it_backup_append() { + local profile_strings=('if [[ -f ~/.profile ]]; then' 'source ~/.profile' 'fi' 'if [[ -f ~/.bashrc ]]; then' 'source ~/.bashrc' 'fi') _bash-it_backup (sed "s|{{BASH_IT}}|$BASH_IT|" "$BASH_IT/template/bash_profile.template.bash" | tail -n +2) >> "$HOME/$CONFIG_FILE" + if [[ ! -f ~/.bash_profile ]]; then + printf '%s\n\t%s\n%s\n%s\n\t%s\n%s\n' "${profile_strings[@]}" > ~/.bash_profile + else + printf '\e[0;33m%s\n\t%s\n\t\t%s\n\t%s\n\t%s\n\t\t%s\n\t%s\n\e[0m' "You may need to update your ~/.bash_profile (or ~/.profile) to source your ~/.bashrc:" "${profile_strings[@]}" + fi echo -e "\033[0;32mBash-it template has been added to your $CONFIG_FILE\033[0m" } @@ -186,14 +192,7 @@ 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 echo "Installing bash-it" @@ -205,13 +204,13 @@ fi 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" +source "${BASH_IT}/vendor/github.com/erichs/composure/composure.sh" cite _about _param _example _group _author _version -# shellcheck source=./lib/helpers.bash +# shellcheck source-path=SCRIPTDIR/lib +source "$BASH_IT/lib/utilities.bash" +# shellcheck source-path=SCRIPTDIR/lib +source "${BASH_IT}/lib/log.bash" +# shellcheck source-path=SCRIPTDIR/lib source "$BASH_IT/lib/helpers.bash" if [[ -n $interactive && -z "${silent}" ]]; then diff --git a/test/install/install.bats b/test/install/install.bats index c9e1794c..d4149bba 100644 --- a/test/install/install.bats +++ b/test/install/install.bats @@ -8,15 +8,7 @@ function local_setup() { function local_setup_file() { # Determine which config file to use based on OS. - case $OSTYPE in - darwin*) - export BASH_IT_CONFIG_FILE=.bash_profile - ;; - *) - export BASH_IT_CONFIG_FILE=.bashrc - ;; - esac - # don't load any libraries as the tests here test the *whole* kit + export BASH_IT_CONFIG_FILE=.bashrc } @test "install: verify that the install script exists" { From 0853724c7d8345c854a62894b99c8e596a570d60 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 28 Jan 2022 14:26:58 -0800 Subject: [PATCH 02/12] install: cleanup --- install.sh | 130 ++++++++---------- ...ile.template.bash => bashrc.template.bash} | 0 2 files changed, 59 insertions(+), 71 deletions(-) rename template/{bash_profile.template.bash => bashrc.template.bash} (100%) diff --git a/install.sh b/install.sh index 927a260b..4c7c1162 100755 --- a/install.sh +++ b/install.sh @@ -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:" @@ -15,41 +15,27 @@ 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 @@ -57,41 +43,35 @@ function _bash-it_load_some() { } # 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() { - local profile_strings=('if [[ -f ~/.profile ]]; then' 'source ~/.profile' 'fi' 'if [[ -f ~/.bashrc ]]; then' 'source ~/.bashrc' 'fi') - _bash-it_backup - (sed "s|{{BASH_IT}}|$BASH_IT|" "$BASH_IT/template/bash_profile.template.bash" | tail -n +2) >> "$HOME/$CONFIG_FILE" - if [[ ! -f ~/.bash_profile ]]; then - printf '%s\n\t%s\n%s\n%s\n\t%s\n%s\n' "${profile_strings[@]}" > ~/.bash_profile - else - printf '\e[0;33m%s\n\t%s\n\t\t%s\n\t%s\n\t%s\n\t\t%s\n\t%s\n\e[0m' "You may need to update your ~/.bash_profile (or ~/.profile) to source your ~/.bashrc:" "${profile_strings[@]}" - fi - 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 @@ -101,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 @@ -132,17 +112,24 @@ 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 + local choice profile_string=$'if [[ -s ~/.profile ]]; then\n\tsource ~/.profile\nfi\nif [[ $- == *"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 } @@ -163,7 +150,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 ;; @@ -172,7 +159,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 @@ -181,42 +168,44 @@ 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)" -CONFIG_FILE=.bashrc +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 +# 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-path=SCRIPTDIR/lib -source "$BASH_IT/lib/utilities.bash" -# shellcheck source-path=SCRIPTDIR/lib source "${BASH_IT}/lib/log.bash" # shellcheck source-path=SCRIPTDIR/lib -source "$BASH_IT/lib/helpers.bash" +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 "" @@ -224,9 +213,8 @@ else 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" diff --git a/template/bash_profile.template.bash b/template/bashrc.template.bash similarity index 100% rename from template/bash_profile.template.bash rename to template/bashrc.template.bash From c3de63b7870644249cb7eeab89e7ee00eaeadd14 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 28 Jan 2022 14:51:28 -0800 Subject: [PATCH 03/12] uninstall: cleanup --- clean_files.txt | 1 + uninstall.sh | 36 +++++++++++++++--------------------- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index e52d5a9f..fca0130c 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -28,6 +28,7 @@ bash_it.sh clean_files.txt install.sh lint_clean_files.sh +uninstall.sh # completions # diff --git a/uninstall.sh b/uninstall.sh index 17712610..032bdb7e 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -1,31 +1,25 @@ #!/usr/bin/env bash -if [ -z "$BASH_IT" ]; -then - BASH_IT="$HOME/.bash_it" -fi +: "${BASH_IT:=${HOME?}/.bash_it}" -case $OSTYPE in - darwin*) - CONFIG_FILE=.bash_profile - ;; - *) - CONFIG_FILE=.bashrc - ;; -esac +CONFIG_FILE=".bashrc" +if [[ ! -e ~/.bashrc && -e ~/.bash_profile ]]; then + # legacy Mac or WSL or just no backup file + CONFIG_FILE=".bash_profile" +fi BACKUP_FILE=$CONFIG_FILE.bak -if [ ! -e "$HOME/$BACKUP_FILE" ]; then - echo -e "\033[0;33mBackup file $HOME/$BACKUP_FILE not found.\033[0m" >&2 +if [[ ! -e "${HOME?}/$BACKUP_FILE" ]]; then + echo -e "\033[0;33mBackup file ${HOME?}/$BACKUP_FILE not found.\033[0m" >&2 - test -w "$HOME/$CONFIG_FILE" && - mv "$HOME/$CONFIG_FILE" "$HOME/$CONFIG_FILE.uninstall" && - echo -e "\033[0;32mMoved your $HOME/$CONFIG_FILE to $HOME/$CONFIG_FILE.uninstall.\033[0m" + test -w "${HOME?}/$CONFIG_FILE" \ + && mv "${HOME?}/$CONFIG_FILE" "${HOME?}/$CONFIG_FILE.uninstall" \ + && echo -e "\033[0;32mMoved your ${HOME?}/$CONFIG_FILE to ${HOME?}/$CONFIG_FILE.uninstall.\033[0m" else - test -w "$HOME/$BACKUP_FILE" && - cp -a "$HOME/$BACKUP_FILE" "$HOME/$CONFIG_FILE" && - rm "$HOME/$BACKUP_FILE" && - echo -e "\033[0;32mYour original $CONFIG_FILE has been restored.\033[0m" + test -w "${HOME?}/$BACKUP_FILE" \ + && cp -a "${HOME?}/$BACKUP_FILE" "${HOME?}/$CONFIG_FILE" \ + && rm "${HOME?}/$BACKUP_FILE" \ + && echo -e "\033[0;32mYour original $CONFIG_FILE has been restored.\033[0m" fi echo "" From d55adc610f6532b13367abeefdd7d26bfd5d66d1 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 28 Jan 2022 16:30:09 -0800 Subject: [PATCH 04/12] docs: fix references to `~/.bashrc` docs/installation: add to note about interactive/login shells --- docs/installation.rst | 14 ++++++-------- docs/themes-list/atomic.rst | 3 +-- docs/themes-list/powerline-base.rst | 2 +- docs/themes-list/powerline-multiline.rst | 2 +- docs/vcs_user.rst | 2 +- 5 files changed, 10 insertions(+), 13 deletions(-) diff --git a/docs/installation.rst b/docs/installation.rst index 9688af20..068f2da5 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -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 @@ -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. @@ -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 `_ or -`iTerm2 `_\ ) 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 `_ to get more info. diff --git a/docs/themes-list/atomic.rst b/docs/themes-list/atomic.rst index 7d471ba9..73197c29 100644 --- a/docs/themes-list/atomic.rst +++ b/docs/themes-list/atomic.rst @@ -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`` `_ or make sure the terminal emulator you use (ej: cygwin, mintty, etc) has the ``sed`` command installed. Command to execute For Windows and Linux: @@ -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 -------- diff --git a/docs/themes-list/powerline-base.rst b/docs/themes-list/powerline-base.rst index faa1af34..3c791d4f 100644 --- a/docs/themes-list/powerline-base.rst +++ b/docs/themes-list/powerline-base.rst @@ -8,7 +8,7 @@ all powerline themes. **IMPORTANT:** This theme requires that `a font with the Powerline symbols `_ 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 -------------------- diff --git a/docs/themes-list/powerline-multiline.rst b/docs/themes-list/powerline-multiline.rst index f525f022..2e9aeb36 100644 --- a/docs/themes-list/powerline-multiline.rst +++ b/docs/themes-list/powerline-multiline.rst @@ -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 diff --git a/docs/vcs_user.rst b/docs/vcs_user.rst index c6d31a57..1c082de7 100644 --- a/docs/vcs_user.rst +++ b/docs/vcs_user.rst @@ -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: From 4c5e87e545b1be553ba773a377b31d75388821ed Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 28 Jan 2022 16:37:25 -0800 Subject: [PATCH 05/12] install: `_bash-it-install-modify-profile()` --- install.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 4c7c1162..00342bfc 100755 --- a/install.sh +++ b/install.sh @@ -124,7 +124,11 @@ function _bash-it-install-modify-config() { # backup/new by default _bash-it-install-backup-new fi - local choice profile_string=$'if [[ -s ~/.profile ]]; then\n\tsource ~/.profile\nfi\nif [[ $- == *"i"* && -s ~/.bashrc ]]; then\n\tsource ~/.bashrc\nfi' + _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 From 0485778117d6d29e511e2b3d11bda89566341fb8 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Tue, 15 Feb 2022 12:58:55 -0800 Subject: [PATCH 06/12] uninstall: //echo/printf MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Alsö, add implementation note at top. --- uninstall.sh | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/uninstall.sh b/uninstall.sh index 032bdb7e..8147943a 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -1,4 +1,8 @@ #!/usr/bin/env bash +# +# Since we're uninstalling, avoid depending on any other part of _Bash It_. +# I.e., hard-code colors (avoid `lib/colors.bash`), &c. + : "${BASH_IT:=${HOME?}/.bash_it}" CONFIG_FILE=".bashrc" @@ -10,21 +14,19 @@ fi BACKUP_FILE=$CONFIG_FILE.bak if [[ ! -e "${HOME?}/$BACKUP_FILE" ]]; then - echo -e "\033[0;33mBackup file ${HOME?}/$BACKUP_FILE not found.\033[0m" >&2 + printf '\e[0;33m%s\e[0m\n' "Backup file ~/$BACKUP_FILE not found." test -w "${HOME?}/$CONFIG_FILE" \ && mv "${HOME?}/$CONFIG_FILE" "${HOME?}/$CONFIG_FILE.uninstall" \ - && echo -e "\033[0;32mMoved your ${HOME?}/$CONFIG_FILE to ${HOME?}/$CONFIG_FILE.uninstall.\033[0m" + && printf '\e[0;32m%s\e[0m\n' "Moved your ~/$CONFIG_FILE to ~/$CONFIG_FILE.uninstall." else test -w "${HOME?}/$BACKUP_FILE" \ && cp -a "${HOME?}/$BACKUP_FILE" "${HOME?}/$CONFIG_FILE" \ && rm "${HOME?}/$BACKUP_FILE" \ - && echo -e "\033[0;32mYour original $CONFIG_FILE has been restored.\033[0m" + && printf '\e[0;32m%s\e[0m\n' "Your original ~/$CONFIG_FILE has been restored." fi -echo "" -echo -e "\033[0;32mUninstallation finished successfully! Sorry to see you go!\033[0m" -echo "" -echo "Final steps to complete the uninstallation:" -echo " -> Remove the $BASH_IT folder" -echo " -> Open a new shell/tab/terminal" +printf '\n\e[0;32m%s\e[0m\n\n' "Uninstallation finished successfully! Sorry to see you go!" +printf '%s\n' "Final steps to complete the uninstallation:" +printf '\t%s\n' "-> Remove the ${BASH_IT//${HOME?}/\~} folder" +printf '\t%s\n' "-> Open a new shell/tab/terminal" From 68149f7c8debc865dad34ad1903d9fa62d92ff92 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 4 Mar 2022 12:29:09 -0800 Subject: [PATCH 07/12] uninstall: try to determine initialization file uninstall: TIL that `fgrep` is deprecated... --- test/install/uninstall.bats | 88 +++++++++++++++++++++++++------------ uninstall.sh | 24 ++++++++-- 2 files changed, 80 insertions(+), 32 deletions(-) diff --git a/test/install/uninstall.bats b/test/install/uninstall.bats index ab71a775..4362574f 100644 --- a/test/install/uninstall.bats +++ b/test/install/uninstall.bats @@ -7,55 +7,85 @@ function local_setup() { } function local_setup_file() { - # Determine which config file to use based on OS. - case $OSTYPE in - darwin*) - export BASH_IT_CONFIG_FILE=.bash_profile - ;; - *) - export BASH_IT_CONFIG_FILE=.bashrc - ;; - esac - # don't load any libraries as the tests here test the *whole* kit + : # don't load any libraries as the tests here test the *whole* kit } @test "uninstall: verify that the uninstall script exists" { assert_file_exist "$BASH_IT/uninstall.sh" } -@test "uninstall: run the uninstall script with an existing backup file" { - cd "$BASH_IT" +@test "uninstall: run the uninstall script with existing backup 'bashrc'" { + BASH_IT_CONFIG_FILE=.bashrc - echo "test file content for backup" > "$HOME/$BASH_IT_CONFIG_FILE.bak" - echo "test file content for original file" > "$HOME/$BASH_IT_CONFIG_FILE" - local md5_bak=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}') + echo "test file content for backup" > "${HOME?}/$BASH_IT_CONFIG_FILE.bak" + echo "test file content for original BASH_IT file" > "${HOME?}/$BASH_IT_CONFIG_FILE" + local md5_bak=$(md5sum "${HOME?}/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}') - run ./uninstall.sh + run "${BASH_IT?}/uninstall.sh" assert_success + assert_output --partial "Your original ~/$BASH_IT_CONFIG_FILE has been restored." - assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE.uninstall" - assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE.bak" - assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE" + assert_file_not_exist "${HOME?}/$BASH_IT_CONFIG_FILE.uninstall" + assert_file_not_exist "${HOME?}/$BASH_IT_CONFIG_FILE.bak" + assert_file_exist "${HOME?}/$BASH_IT_CONFIG_FILE" - local md5_conf=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}') + local md5_conf=$(md5sum "${HOME?}/$BASH_IT_CONFIG_FILE" | awk '{print $1}') assert_equal "$md5_bak" "$md5_conf" } -@test "uninstall: run the uninstall script without an existing backup file" { - cd "$BASH_IT" +@test "uninstall: run the uninstall script with existing backup 'bash_profile'" { + BASH_IT_CONFIG_FILE=.bash_profile - echo "test file content for original file" > "$HOME/$BASH_IT_CONFIG_FILE" - local md5_orig=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}') + echo "test file content for backup file" > "${HOME?}/$BASH_IT_CONFIG_FILE.bak" + echo "test file content for original BASH_IT file" > "${HOME?}/$BASH_IT_CONFIG_FILE" + local md5_bak=$(md5sum "${HOME?}/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}') - run ./uninstall.sh + run "${BASH_IT?}/uninstall.sh" assert_success - assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE.uninstall" - assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE.bak" - assert_file_not_exist "$HOME/$BASH_IT_CONFIG_FILE" + assert_file_not_exist "${HOME?}/$BASH_IT_CONFIG_FILE.uninstall" + assert_file_not_exist "${HOME?}/$BASH_IT_CONFIG_FILE.bak" + assert_file_exist "${HOME?}/$BASH_IT_CONFIG_FILE" - local md5_uninstall=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.uninstall" | awk '{print $1}') + local md5_conf=$(md5sum "${HOME?}/$BASH_IT_CONFIG_FILE" | awk '{print $1}') + + assert_equal "$md5_bak" "$md5_conf" +} + +@test "uninstall: run the uninstall script without existing backup 'bashrc" { + BASH_IT_CONFIG_FILE=.bashrc + + echo "test file content for original BASH_IT file" > "${HOME?}/$BASH_IT_CONFIG_FILE" + local md5_orig=$(md5sum "${HOME?}/$BASH_IT_CONFIG_FILE" | awk '{print $1}') + + run "${BASH_IT?}/uninstall.sh" + assert_success + + assert_file_exist "${HOME?}/$BASH_IT_CONFIG_FILE.uninstall" + assert_file_not_exist "${HOME?}/$BASH_IT_CONFIG_FILE.bak" + assert_file_not_exist "${HOME?}/$BASH_IT_CONFIG_FILE" + + local md5_uninstall=$(md5sum "${HOME?}/$BASH_IT_CONFIG_FILE.uninstall" | awk '{print $1}') + + assert_equal "$md5_orig" "$md5_uninstall" +} + +@test "uninstall: run the uninstall script without existing backup 'bash_profile" { + BASH_IT_CONFIG_FILE=.bash_profile + + echo "test file content for original BASH_IT file" > "${HOME?}/$BASH_IT_CONFIG_FILE" + local md5_orig=$(md5sum "${HOME?}/$BASH_IT_CONFIG_FILE" | awk '{print $1}') + + run "${BASH_IT?}/uninstall.sh" + + assert_success + + assert_file_exist "${HOME?}/$BASH_IT_CONFIG_FILE.uninstall" + assert_file_not_exist "${HOME?}/$BASH_IT_CONFIG_FILE.bak" + assert_file_not_exist "${HOME?}/$BASH_IT_CONFIG_FILE" + + local md5_uninstall=$(md5sum "${HOME?}/$BASH_IT_CONFIG_FILE.uninstall" | awk '{print $1}') assert_equal "$md5_orig" "$md5_uninstall" } diff --git a/uninstall.sh b/uninstall.sh index 8147943a..e593d66d 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -5,12 +5,30 @@ : "${BASH_IT:=${HOME?}/.bash_it}" -CONFIG_FILE=".bashrc" -if [[ ! -e ~/.bashrc && -e ~/.bash_profile ]]; then - # legacy Mac or WSL or just no backup file +if [[ ! -e ~/.bashrc && ! -e ~/.bash_profile && ! -e ~/.bashrc.bak && ! -e ~/.bash_profile.bak ]]; then + echo "We can't locate your configuration files, so we can't uninstall..." + return +elif grep -F -q -- BASH_IT ~/.bashrc && grep -F -q -- BASH_IT ~/.bash_profile; then + echo "We can't figure out if Bash-it is loaded from ~/.bashrc or ~/.bash_profile..." + return +elif grep -F -q -- BASH_IT ~/.bashrc || [[ -e ~/.bashrc.bak && ! -e ~/.bashrc ]]; then + CONFIG_FILE=".bashrc" +elif grep -F -q -- BASH_IT ~/.bash_profile || [[ -e ~/.bash_profile.bak && ! -e ~/.bash_profile ]]; then CONFIG_FILE=".bash_profile" +else + echo "Bash-it does not appear to be installed." + return fi +# possible states: +# - both .bash* /and/ .bash*.bak, /and/ both config reference `$BASH_IT`: no solution +# - both config and bak, but only one references `$BASH_IT`: that one +# - both config, only one bak, but other references `$BASH_IT`: the other one? +# - both config, no bak, with `$BASH_IT` reference: that one +# - one config, no bak, but no `$BASH_IT` reference: wut +# - no config, with bak, with `$BASH_IT`: re-create??? +# - no config, no bak: nothing. + BACKUP_FILE=$CONFIG_FILE.bak if [[ ! -e "${HOME?}/$BACKUP_FILE" ]]; then From 52cd75b27e9beb8b9ae4f04868b39c76ea0bc145 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 12 Feb 2022 00:07:53 -0800 Subject: [PATCH 08/12] template: `shfmt` --- clean_files.txt | 1 + template/bashrc.template.bash | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) mode change 100755 => 100644 template/bashrc.template.bash diff --git a/clean_files.txt b/clean_files.txt index fca0130c..878e8355 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -20,6 +20,7 @@ aliases/ docs/ hooks/ scripts/ +template/ # root files # diff --git a/template/bashrc.template.bash b/template/bashrc.template.bash old mode 100755 new mode 100644 index 3def2866..478cbc98 --- a/template/bashrc.template.bash +++ b/template/bashrc.template.bash @@ -2,8 +2,8 @@ # If not running interactively, don't do anything case $- in - *i*) ;; - *) return;; + *i*) ;; + *) return ;; esac # Path to the bash it configuration From affbce6de18e8f2371c374cae58c02a915a42c93 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 12 Feb 2022 00:14:12 -0800 Subject: [PATCH 09/12] template: `shellcheck` - and generally comment out useless varbls --- template/bashrc.template.bash | 40 ++++++++++++++++++----------------- test/install/install.bats | 2 +- 2 files changed, 22 insertions(+), 20 deletions(-) mode change 100644 => 100755 test/install/install.bats diff --git a/template/bashrc.template.bash b/template/bashrc.template.bash index 478cbc98..20bd3ca6 100644 --- a/template/bashrc.template.bash +++ b/template/bashrc.template.bash @@ -1,4 +1,5 @@ -#!/usr/bin/env bash +# shellcheck shell=bash +# shellcheck disable=SC2034 # If not running interactively, don't do anything case $- in @@ -7,12 +8,12 @@ case $- in esac # Path to the bash it configuration -export BASH_IT="{{BASH_IT}}" +BASH_IT="{{BASH_IT}}" # Lock and Load a custom theme file. # Leave empty to disable theming. -# location /.bash_it/themes/ -export BASH_IT_THEME='bobby' +# location ~/.bash_it/themes/ +BASH_IT_THEME='bobby' # Some themes can show whether `sudo` has a current token or not. # Set `$THEME_CHECK_SUDO` to `true` to check every prompt: @@ -20,14 +21,14 @@ export BASH_IT_THEME='bobby' # (Advanced): Change this to the name of your remote repo if you # cloned bash-it with a remote other than origin such as `bash-it`. -# export BASH_IT_REMOTE='bash-it' +#BASH_IT_REMOTE='bash-it' # (Advanced): Change this to the name of the main development branch if # you renamed it or if it was changed for some reason -# export BASH_IT_DEVELOPMENT_BRANCH='master' +#BASH_IT_DEVELOPMENT_BRANCH='master' # Your place for hosting Git repos. I use this for private repos. -export GIT_HOSTING='git@git.domain.com' +#GIT_HOSTING='git@git.domain.com' # Don't check mail when opening terminal. unset MAILCHECK @@ -36,49 +37,50 @@ unset MAILCHECK export IRC_CLIENT='irssi' # Set this to the command you use for todo.txt-cli -export TODO="t" +TODO="t" # Set this to the location of your work or project folders #BASH_IT_PROJECT_PATHS="${HOME}/Projects:/Volumes/work/src" # Set this to false to turn off version control status checking within the prompt for all themes -export SCM_CHECK=true +#SCM_CHECK=true + # Set to actual location of gitstatus directory if installed -#export SCM_GIT_GITSTATUS_DIR="$HOME/gitstatus" +#SCM_GIT_GITSTATUS_DIR="$HOME/gitstatus" # per default gitstatus uses 2 times as many threads as CPU cores, you can change this here if you must #export GITSTATUS_NUM_THREADS=8 # Set Xterm/screen/Tmux title with only a short hostname. # Uncomment this (or set SHORT_HOSTNAME to something else), # Will otherwise fall back on $HOSTNAME. -#export SHORT_HOSTNAME=$(hostname -s) +#SHORT_HOSTNAME=$(hostname -s) # Set Xterm/screen/Tmux title with only a short username. # Uncomment this (or set SHORT_USER to something else), # Will otherwise fall back on $USER. -#export SHORT_USER=${USER:0:8} +#SHORT_USER=${USER:0:8} # If your theme use command duration, uncomment this to # enable display of last command duration. -#export BASH_IT_COMMAND_DURATION=true +#BASH_IT_COMMAND_DURATION=true # You can choose the minimum time in seconds before # command duration is displayed. -#export COMMAND_DURATION_MIN_SECONDS=1 +#COMMAND_DURATION_MIN_SECONDS=1 # Set Xterm/screen/Tmux title with shortened command and directory. # Uncomment this to set. -#export SHORT_TERM_LINE=true +#SHORT_TERM_LINE=true # Set vcprompt executable path for scm advance info in prompt (demula theme) # https://github.com/djl/vcprompt -#export VCPROMPT_EXECUTABLE=~/.vcprompt/bin/vcprompt +#VCPROMPT_EXECUTABLE=~/.vcprompt/bin/vcprompt # (Advanced): Uncomment this to make Bash-it reload itself automatically # after enabling or disabling aliases, plugins, and completions. -# export BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE=1 +# BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE=1 # Uncomment this to make Bash-it create alias reload. -# export BASH_IT_RELOAD_LEGACY=1 +# BASH_IT_RELOAD_LEGACY=1 # Load Bash It -source "$BASH_IT"/bash_it.sh +source "${BASH_IT?}/bash_it.sh" diff --git a/test/install/install.bats b/test/install/install.bats old mode 100644 new mode 100755 index d4149bba..1bbbda70 --- a/test/install/install.bats +++ b/test/install/install.bats @@ -76,5 +76,5 @@ function local_setup_file() { run cat "$HOME/$BASH_IT_CONFIG_FILE" assert_line "test file content" - assert_line "source \"\$BASH_IT\"/bash_it.sh" + assert_line 'source "${BASH_IT?}/bash_it.sh"' } From 8a6debd9d279e2f418a3b3a043fd0b300d2d66da Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 4 Mar 2022 13:05:56 -0800 Subject: [PATCH 10/12] lint: add lib to clean_files.txt --- clean_files.txt | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 878e8355..ba2e7704 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -19,6 +19,7 @@ aliases/ docs/ hooks/ +lib/ scripts/ template/ @@ -77,18 +78,6 @@ completion/available/vault.completion.bash completion/available/vuejs.completion.bash completion/available/wpscan.completion.bash -# libraries -lib/appearance.bash -lib/colors.bash -lib/command_duration.bash -lib/helpers.bash -lib/history.bash -lib/log.bash -lib/preexec.bash -lib/preview.bash -lib/search.bash -lib/utilities.bash - # plugins # plugins/available/alias-completion.plugin.bash From c09c050325c29af7ddda478ac622c3ebee3ba3bf Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 20 Feb 2022 11:03:33 -0800 Subject: [PATCH 11/12] Revert "bash_it: source reloader.bash without arguments for the default enabling" This reverts commit e05fa477d70a793ec6dd23358ecc8a16ad45126f. This reverts commit ee853670a11906029ba5df1ef9402cdbb65f6370. --- bash_it.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bash_it.sh b/bash_it.sh index ddc02b70..f3d9c2e9 100755 --- a/bash_it.sh +++ b/bash_it.sh @@ -38,8 +38,7 @@ done # "_bash_it_main_file_type" param is empty so that files get sourced in glob order for _bash_it_main_file_type in "" "aliases" "plugins" "completion"; do BASH_IT_LOG_PREFIX="core: reloader: " - # shellcheck disable=SC2140 - source "${BASH_IT}/scripts/reloader.bash" ${_bash_it_main_file_type:+"skip" "$_bash_it_main_file_type"} + source "${BASH_IT}/scripts/reloader.bash" "${_bash_it_main_file_type:+skip}" "$_bash_it_main_file_type" BASH_IT_LOG_PREFIX="core: main: " done From d0e617a2997b5eaa9028a387ae08c4820bc26e1d Mon Sep 17 00:00:00 2001 From: John D Pell Date: Fri, 24 Sep 2021 00:09:50 -0700 Subject: [PATCH 12/12] custom/example: `shellcheck` c --- clean_files.txt | 1 + custom/example.bash | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/clean_files.txt b/clean_files.txt index ba2e7704..60717004 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -17,6 +17,7 @@ # root directories # aliases/ +custom/ docs/ hooks/ lib/ diff --git a/custom/example.bash b/custom/example.bash index 3e66ba80..05653f1f 100644 --- a/custom/example.bash +++ b/custom/example.bash @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +# shellcheck shell=bash # # This is an example file. Don't use this for your custom scripts. Instead, create another file within the # custom directory.