diff --git a/aliases/available/general.aliases.bash b/aliases/available/general.aliases.bash index df54781b6a..35a956bc86 100644 --- a/aliases/available/general.aliases.bash +++ b/aliases/available/general.aliases.bash @@ -2,6 +2,19 @@ # shellcheck source-path=SCRIPTDIR about-alias 'general aliases' +if command ls --color -d . &> /dev/null; then + alias ls='ls --color=auto' + # BSD `ls` doesn't need an argument (`-G`) when `$CLICOLOR` is set. +fi + +# List directory contents +alias sl=ls +alias la='ls -AF' # Compact view, show hidden +alias ll='ls -Al' +alias l='ls -A' +alias l1='ls -1' +alias lf='ls -F' + alias _='sudo' # colored grep @@ -58,7 +71,12 @@ alias rd='rmdir' alias rmrf='rm -rf' # Shorten extract -alias xt='extract' +_command_exists 'extract' \ + && alias xt='extract' + +# sudo editors +alias svim='sudo "${VISUAL:-vim}"' +alias snano='sudo "${ALTERNATE_EDITOR:-nano}"' # Display whatever file is regular file or folder function catt() { diff --git a/bash_it.sh b/bash_it.sh index ddc02b708f..19a26ed965 100755 --- a/bash_it.sh +++ b/bash_it.sh @@ -22,11 +22,9 @@ _bash_it_library_finalize_hook=() # We need to load logging module early in order to be able to log source "${BASH_IT}/lib/log.bash" -# libraries, but skip appearance (themes) for now -_log_debug "Loading libraries(except appearance)..." -APPEARANCE_LIB="${BASH_IT}/lib/appearance.bash" +# Load libraries +_log_debug "Loading libraries..." for _bash_it_main_file_lib in "${BASH_IT}/lib"/*.bash; do - [[ "$_bash_it_main_file_lib" == "$APPEARANCE_LIB" ]] && continue _bash-it-log-prefix-by-path "${_bash_it_main_file_lib}" _log_debug "Loading library file..." # shellcheck disable=SC1090 @@ -55,10 +53,14 @@ if [[ -n "${BASH_IT_THEME:-}" ]]; then source "${BASH_IT}/themes/base.theme.bash" BASH_IT_LOG_PREFIX="lib: appearance: " - # appearance (themes) now, after all dependencies - # shellcheck source=SCRIPTDIR/lib/appearance.bash - source "$APPEARANCE_LIB" - BASH_IT_LOG_PREFIX="core: main: " + # shellcheck disable=SC1090 + if [[ -f "${BASH_IT_THEME}" ]]; then + source "${BASH_IT_THEME}" + elif [[ -f "$CUSTOM_THEME_DIR/$BASH_IT_THEME/$BASH_IT_THEME.theme.bash" ]]; then + source "$CUSTOM_THEME_DIR/$BASH_IT_THEME/$BASH_IT_THEME.theme.bash" + elif [[ -f "$BASH_IT/themes/$BASH_IT_THEME/$BASH_IT_THEME.theme.bash" ]]; then + source "$BASH_IT/themes/$BASH_IT_THEME/$BASH_IT_THEME.theme.bash" + fi fi _log_debug "Loading custom aliases, completion, plugins..." diff --git a/clean_files.txt b/clean_files.txt index bfc5596144..8bfc2b0e7c 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -23,6 +23,7 @@ hooks/ lib/ plugins/ scripts/ +template/ test/ # root files @@ -32,6 +33,7 @@ bash_it.sh clean_files.txt install.sh lint_clean_files.sh +uninstall.sh # themes # diff --git a/docs/installation.rst b/docs/installation.rst index 9688af20f7..068f2da572 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 7d471ba908..73197c29ea 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 f38f940daa..b23068191f 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 -------------------- @@ -24,7 +24,7 @@ Provided Information * An indicator when connected by SSH * An indicator when ``sudo`` has the credentials cached (see the ``sudo`` manpage for more info about this) * An indicator when the current shell is inside the Vim editor -* Battery charging status (depends on the battery plugin) +* Battery charging status (depends on the battery library) * SCM Repository status (e.g. Git, SVN) * The current Kubernetes environment * The current Python environment (Virtualenv, venv, and Conda are supported) in use diff --git a/docs/themes-list/powerline-multiline.rst b/docs/themes-list/powerline-multiline.rst index f525f02230..2e9aeb36ab 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 c6d31a5795..1c082de76c 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: diff --git a/install.sh b/install.sh index 4063f516ed..b1ea9bcf4a 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:" @@ -14,41 +14,27 @@ function _bash-it_show_usage() { echo "--overwrite-backup (-f): Overwrite existing backup" } -# 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 @@ -56,35 +42,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() { - _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 @@ -94,28 +80,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 @@ -125,17 +111,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 } @@ -156,7 +153,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 ;; @@ -165,7 +162,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 @@ -174,25 +171,18 @@ 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" # overriding CONFIG_FILE: CONFIG_FILE="${BASH_IT_CONFIG_FILE:-"${CONFIG_FILE}"}" @@ -201,29 +191,31 @@ if [[ "${CONFIG_FILE%/*}" != "${CONFIG_FILE}" ]]; then mkdir -p "${HOME}/${CONFIG_FILE%/*}" fi -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 "" @@ -231,9 +223,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/lib/appearance.bash b/lib/appearance.bash deleted file mode 100644 index e77a1a8032..0000000000 --- a/lib/appearance.bash +++ /dev/null @@ -1,18 +0,0 @@ -# shellcheck shell=bash - -: "${CLICOLOR:=$(tput colors)}" -export CLICOLOR - -: "${CUSTOM_THEME_DIR:="${BASH_IT_CUSTOM:=${BASH_IT}/custom}/themes"}" - -# Load the theme -# shellcheck disable=SC1090 -if [[ -n "${BASH_IT_THEME:-}" ]]; then - if [[ -f "${BASH_IT_THEME}" ]]; then - source "${BASH_IT_THEME}" - elif [[ -f "$CUSTOM_THEME_DIR/$BASH_IT_THEME/$BASH_IT_THEME.theme.bash" ]]; then - source "$CUSTOM_THEME_DIR/$BASH_IT_THEME/$BASH_IT_THEME.theme.bash" - else - source "$BASH_IT/themes/$BASH_IT_THEME/$BASH_IT_THEME.theme.bash" - fi -fi diff --git a/plugins/available/battery.plugin.bash b/lib/battery.bash similarity index 100% rename from plugins/available/battery.plugin.bash rename to lib/battery.bash diff --git a/lib/helpers.bash b/lib/helpers.bash index f9d7b000d7..919540bea6 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -3,7 +3,7 @@ # # A collection of reusable functions. -: "${BASH_IT_LOAD_PRIORITY_ALIAS:=150}" +: "${BASH_IT_LOAD_PRIORITY_ALIAS:=750}" : "${BASH_IT_LOAD_PRIORITY_PLUGIN:=250}" : "${BASH_IT_LOAD_PRIORITY_COMPLETION:=350}" BASH_IT_LOAD_PRIORITY_SEPARATOR="---" diff --git a/plugins/available/blesh.plugin.bash b/plugins/available/blesh.plugin.bash index 083f31ae57..202a4d3bb1 100644 --- a/plugins/available/blesh.plugin.bash +++ b/plugins/available/blesh.plugin.bash @@ -1,8 +1,7 @@ # shellcheck shell=bash -cite about-plugin about-plugin 'load ble.sh, the Bash line editor!' -if [[ ${BLE_VERSION-} ]]; then +if [[ -n "${BLE_VERSION-}" ]]; then _log_warning "ble.sh is already loaded!" return fi diff --git a/plugins/available/go.plugin.bash b/plugins/available/go.plugin.bash index 5592a006a7..9c503319f0 100644 --- a/plugins/available/go.plugin.bash +++ b/plugins/available/go.plugin.bash @@ -19,18 +19,14 @@ export GOPATH="${GOPATH:-$(go env GOPATH)}" _bash-it-gopath-pathmunge() { _about 'Ensures paths in GOPATH are added to PATH using pathmunge, with /bin appended' _group 'go' - if [[ -z $GOPATH ]]; then - echo 'GOPATH empty' >&2 + if [[ -z "${GOPATH:-}" ]]; then + _log_warning 'GOPATH empty' return 1 fi - local paths i + local paths apath IFS=: read -r -a paths <<< "$GOPATH" - i=${#paths[@]} - while [[ $i -gt 0 ]]; do - i=$((i - 1)) - if [[ -n "${paths[i]}" ]]; then - pathmunge "${paths[i]}/bin" - fi + for apath in "${paths[@]}"; do + pathmunge "${apath}/bin" || true done } _bash-it-gopath-pathmunge diff --git a/plugins/available/ruby.plugin.bash b/plugins/available/ruby.plugin.bash index aed8daf8cd..37f8ceb529 100644 --- a/plugins/available/ruby.plugin.bash +++ b/plugins/available/ruby.plugin.bash @@ -5,7 +5,9 @@ about-plugin 'ruby and rubygems specific functions and settings' # Make commands installed with 'gem install --user-install' available # ~/.gem/ruby/${RUBY_VERSION}/bin/ if _command_exists ruby && _command_exists gem; then - pathmunge "$(ruby -e 'print Gem.user_dir')/bin" after + pathmunge "$(ruby -e 'print Gem.user_dir')/bin" after || true +else + _log_warning "Unable to load Ruby plugin as a working 'ruby', or 'gem', was not found." fi function remove_gem() { diff --git a/plugins/available/xterm.plugin.bash b/plugins/available/xterm.plugin.bash index 740460e491..329212edfd 100644 --- a/plugins/available/xterm.plugin.bash +++ b/plugins/available/xterm.plugin.bash @@ -2,7 +2,7 @@ cite about-plugin about-plugin 'automatically set your xterm title with host and location info' -_short-dirname() { +function _short-dirname() { local dir_name="${PWD/~/\~}" if [[ "${SHORT_TERM_LINE:-}" == true && "${#dir_name}" -gt 8 ]]; then echo "${dir_name##*/}" @@ -11,7 +11,7 @@ _short-dirname() { fi } -_short-command() { +function _short-command() { local input_command="$*" if [[ "${SHORT_TERM_LINE:-}" == true && "${#input_command}" -gt 8 ]]; then echo "${input_command%% *}" @@ -20,16 +20,16 @@ _short-command() { fi } -set_xterm_title() { +function set_xterm_title() { local title="${1:-}" echo -ne "\033]0;${title}\007" } -precmd_xterm_title() { +function precmd_xterm_title() { set_xterm_title "${SHORT_USER:-${USER}}@${SHORT_HOSTNAME:-${HOSTNAME}} $(_short-dirname) ${PROMPT_CHAR:-\$}" } -preexec_xterm_title() { +function preexec_xterm_title() { local command_line="${BASH_COMMAND:-${1:-}}" local directory_name short_command directory_name="$(_short-dirname)" @@ -38,8 +38,8 @@ preexec_xterm_title() { } case "${TERM:-dumb}" in - xterm* | rxvt*) - precmd_functions+=(precmd_xterm_title) - preexec_functions+=(preexec_xterm_title) + xterm* | rxvt* | gnome-terminal | konsole | zvt | dtterm | kterm | Eterm | zterm) + safe_append_prompt_command 'precmd_xterm_title' + safe_append_preexec 'preexec_xterm_title' ;; esac diff --git a/template/bash_profile.template.bash b/template/bashrc.template.bash old mode 100755 new mode 100644 similarity index 68% rename from template/bash_profile.template.bash rename to template/bashrc.template.bash index c331dd8964..4b07c32fed --- a/template/bash_profile.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,7 +8,7 @@ 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. @@ -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,40 @@ 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) - -# 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} - # 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/bash_it/bash_it.bats b/test/bash_it/bash_it.bats index e43ab988cd..c86e043e46 100644 --- a/test/bash_it/bash_it.bats +++ b/test/bash_it/bash_it.bats @@ -14,18 +14,23 @@ function local_setup_file() { } @test "bash-it: load aliases in order" { - ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" + run ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" - ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/150---a.aliases.bash" + run ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/150---a.aliases.bash" assert_link_exist "${BASH_IT?}/aliases/enabled/150---a.aliases.bash" - ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" + run ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" assert_link_exist "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null assert_failure + run ln -s "$BASH_IT/aliases/available/a.aliases.bash" "$BASH_IT/aliases/enabled/750---a.aliases.bash" + assert_link_exist "$BASH_IT/aliases/enabled/750---a.aliases.bash" + run ln -s "$BASH_IT/aliases/available/b.aliases.bash" "$BASH_IT/aliases/enabled/750---b.aliases.bash" + assert_link_exist "$BASH_IT/aliases/enabled/750---b.aliases.bash" + load "${BASH_IT?}/bash_it.sh" run alias test_alias &> /dev/null @@ -34,18 +39,23 @@ function local_setup_file() { } @test "bash-it: load aliases in priority order" { - ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" + run ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" - ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/175---a.aliases.bash" + run ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/175---a.aliases.bash" assert_link_exist "${BASH_IT?}/aliases/enabled/175---a.aliases.bash" - ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" + run ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" assert_link_exist "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null assert_failure + run ln -s "$BASH_IT/aliases/available/a.aliases.bash" "$BASH_IT/aliases/enabled/755---a.aliases.bash" + assert_link_exist "$BASH_IT/aliases/enabled/755---a.aliases.bash" + run ln -s "$BASH_IT/aliases/available/b.aliases.bash" "$BASH_IT/aliases/enabled/750---b.aliases.bash" + assert_link_exist "$BASH_IT/aliases/enabled/750---b.aliases.bash" + load "${BASH_IT?}/bash_it.sh" run alias test_alias &> /dev/null @@ -54,20 +64,27 @@ function local_setup_file() { } @test "bash-it: load aliases and plugins in priority order" { - ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" + run ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" - ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/150---a.aliases.bash" + run ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/150---a.aliases.bash" assert_link_exist "${BASH_IT?}/aliases/enabled/150---a.aliases.bash" - ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" + run ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" assert_link_exist "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" - ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/plugins/enabled/250---c.plugin.bash" + run ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/plugins/enabled/250---c.plugin.bash" assert_link_exist "${BASH_IT?}/plugins/enabled/250---c.plugin.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null assert_failure + run ln -s "$BASH_IT/aliases/available/a.aliases.bash" "$BASH_IT/aliases/enabled/750---a.aliases.bash" + assert_link_exist "$BASH_IT/aliases/enabled/750---a.aliases.bash" + run ln -s "$BASH_IT/aliases/available/b.aliases.bash" "$BASH_IT/aliases/enabled/750---b.aliases.bash" + assert_link_exist "$BASH_IT/aliases/enabled/750---b.aliases.bash" + run ln -s "$BASH_IT/plugins/available/c.plugin.bash" "$BASH_IT/plugins/enabled/250---c.plugin.bash" + assert_link_exist "$BASH_IT/plugins/enabled/250---c.plugin.bash" + load "${BASH_IT?}/bash_it.sh" run alias test_alias &> /dev/null @@ -76,20 +93,27 @@ function local_setup_file() { } @test "bash-it: load aliases, plugins and completions in priority order" { - ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" + run ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" - ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/150---a.aliases.bash" + run ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/150---a.aliases.bash" assert_link_exist "${BASH_IT?}/aliases/enabled/150---a.aliases.bash" - ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/completion/enabled/350---b.completion.bash" + run ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/completion/enabled/350---b.completion.bash" assert_link_exist "${BASH_IT?}/completion/enabled/350---b.completion.bash" - ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/plugins/enabled/250---c.plugin.bash" + run ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/plugins/enabled/250---c.plugin.bash" assert_link_exist "${BASH_IT?}/plugins/enabled/250---c.plugin.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null assert_failure + run ln -s "$BASH_IT/aliases/available/a.aliases.bash" "$BASH_IT/aliases/enabled/750---a.aliases.bash" + assert_link_exist "$BASH_IT/aliases/enabled/750---a.aliases.bash" + run ln -s "$BASH_IT/aliases/available/b.aliases.bash" "$BASH_IT/completion/enabled/350---b.completion.bash" + assert_link_exist "$BASH_IT/completion/enabled/350---b.completion.bash" + run ln -s "$BASH_IT/plugins/available/c.plugin.bash" "$BASH_IT/plugins/enabled/250---c.plugin.bash" + assert_link_exist "$BASH_IT/plugins/enabled/250---c.plugin.bash" + load "${BASH_IT?}/bash_it.sh" run alias test_alias &> /dev/null @@ -99,14 +123,14 @@ function local_setup_file() { } @test "bash-it: load aliases, plugins and completions in priority order, even if the priority says otherwise" { - ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" + run ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" - ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/450---a.aliases.bash" + run ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/450---a.aliases.bash" assert_link_exist "${BASH_IT?}/aliases/enabled/450---a.aliases.bash" - ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/completion/enabled/350---b.completion.bash" + run ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/completion/enabled/350---b.completion.bash" assert_link_exist "${BASH_IT?}/completion/enabled/350---b.completion.bash" - ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/plugins/enabled/950---c.plugin.bash" + run ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/plugins/enabled/950---c.plugin.bash" assert_link_exist "${BASH_IT?}/plugins/enabled/950---c.plugin.bash" # The `test_alias` alias should not exist @@ -122,20 +146,27 @@ function local_setup_file() { } @test "bash-it: load aliases and plugins in priority order, with one alias higher than plugins" { - ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" + run ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" - ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/350---a.aliases.bash" + run ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/aliases/enabled/350---a.aliases.bash" assert_link_exist "${BASH_IT?}/aliases/enabled/350---a.aliases.bash" - ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" + run ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" assert_link_exist "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" - ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/plugins/enabled/250---c.plugin.bash" + run ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/plugins/enabled/250---c.plugin.bash" assert_link_exist "${BASH_IT?}/plugins/enabled/250---c.plugin.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null assert_failure + run ln -s "$BASH_IT/aliases/available/a.aliases.bash" "$BASH_IT/aliases/enabled/350---a.aliases.bash" + assert_link_exist "$BASH_IT/aliases/enabled/350---a.aliases.bash" + run ln -s "$BASH_IT/aliases/available/b.aliases.bash" "$BASH_IT/aliases/enabled/750---b.aliases.bash" + assert_link_exist "$BASH_IT/aliases/enabled/750---b.aliases.bash" + run ln -s "$BASH_IT/plugins/available/c.plugin.bash" "$BASH_IT/plugins/enabled/250---c.plugin.bash" + assert_link_exist "$BASH_IT/plugins/enabled/250---c.plugin.bash" + load "${BASH_IT?}/bash_it.sh" run alias test_alias &> /dev/null @@ -146,18 +177,23 @@ function local_setup_file() { } @test "bash-it: load global aliases in order" { - ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash" + run ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" - ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/enabled/150---a.aliases.bash" + run ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/enabled/150---a.aliases.bash" assert_link_exist "${BASH_IT?}/enabled/150---a.aliases.bash" - ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/enabled/150---b.aliases.bash" + run ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/enabled/150---b.aliases.bash" assert_link_exist "${BASH_IT?}/enabled/150---b.aliases.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null assert_failure + run ln -s "$BASH_IT/aliases/available/a.aliases.bash" "$BASH_IT/enabled/750---a.aliases.bash" + assert_link_exist "$BASH_IT/enabled/750---a.aliases.bash" + run ln -s "$BASH_IT/aliases/available/b.aliases.bash" "$BASH_IT/enabled/750---b.aliases.bash" + assert_link_exist "$BASH_IT/enabled/750---b.aliases.bash" + load "${BASH_IT?}/bash_it.sh" run alias test_alias &> /dev/null @@ -166,18 +202,23 @@ function local_setup_file() { } @test "bash-it: load global aliases in priority order" { - ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash" + run ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" - ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/enabled/175---a.aliases.bash" + run ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/enabled/175---a.aliases.bash" assert_link_exist "${BASH_IT?}/enabled/175---a.aliases.bash" - ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/enabled/150---b.aliases.bash" + run ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/enabled/150---b.aliases.bash" assert_link_exist "${BASH_IT?}/enabled/150---b.aliases.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null assert_failure + run ln -s "$BASH_IT/aliases/available/a.aliases.bash" "$BASH_IT/enabled/755---a.aliases.bash" + assert_link_exist "$BASH_IT/enabled/755---a.aliases.bash" + run ln -s "$BASH_IT/aliases/available/b.aliases.bash" "$BASH_IT/enabled/750---b.aliases.bash" + assert_link_exist "$BASH_IT/enabled/750---b.aliases.bash" + load "${BASH_IT?}/bash_it.sh" run alias test_alias &> /dev/null @@ -186,20 +227,27 @@ function local_setup_file() { } @test "bash-it: load global aliases and plugins in priority order" { - ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash" + run ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" - ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/enabled/150---a.aliases.bash" + run ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/enabled/150---a.aliases.bash" assert_link_exist "${BASH_IT?}/enabled/150---a.aliases.bash" - ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/enabled/150---b.aliases.bash" + run ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/enabled/150---b.aliases.bash" assert_link_exist "${BASH_IT?}/enabled/150---b.aliases.bash" - ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/enabled/250---c.plugin.bash" + run ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/enabled/250---c.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/250---c.plugin.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null assert_failure + run ln -s "$BASH_IT/aliases/available/a.aliases.bash" "$BASH_IT/enabled/755---a.aliases.bash" + assert_link_exist "$BASH_IT/enabled/755---a.aliases.bash" + run ln -s "$BASH_IT/aliases/available/b.aliases.bash" "$BASH_IT/enabled/750---b.aliases.bash" + assert_link_exist "$BASH_IT/enabled/750---b.aliases.bash" + run ln -s "$BASH_IT/plugins/available/c.plugin.bash" "$BASH_IT/enabled/850---c.plugin.bash" + assert_link_exist "$BASH_IT/enabled/850---c.plugin.bash" + load "${BASH_IT?}/bash_it.sh" run alias test_alias &> /dev/null @@ -208,20 +256,27 @@ function local_setup_file() { } @test "bash-it: load global aliases and plugins in priority order, with one alias higher than plugins" { - ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash" + run ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" - ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/enabled/350---a.aliases.bash" + run ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/enabled/350---a.aliases.bash" assert_link_exist "${BASH_IT?}/enabled/350---a.aliases.bash" - ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/enabled/150---b.aliases.bash" + run ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/enabled/150---b.aliases.bash" assert_link_exist "${BASH_IT?}/enabled/150---b.aliases.bash" - ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/enabled/250---c.plugin.bash" + run ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/enabled/250---c.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/250---c.plugin.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null assert_failure + run ln -s "$BASH_IT/aliases/available/a.aliases.bash" "$BASH_IT/enabled/950---a.aliases.bash" + assert_link_exist "$BASH_IT/enabled/950---a.aliases.bash" + run ln -s "$BASH_IT/aliases/available/b.aliases.bash" "$BASH_IT/enabled/750---b.aliases.bash" + assert_link_exist "$BASH_IT/enabled/750---b.aliases.bash" + run ln -s "$BASH_IT/plugins/available/c.plugin.bash" "$BASH_IT/enabled/850---c.plugin.bash" + assert_link_exist "$BASH_IT/enabled/850---c.plugin.bash" + load "${BASH_IT?}/bash_it.sh" run alias test_alias &> /dev/null @@ -232,23 +287,33 @@ function local_setup_file() { } @test "bash-it: load global aliases and plugins in priority order, individual old directories are loaded later" { - ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash" + run ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" - ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/enabled/350---a.aliases.bash" + run ln -s "${BASH_IT?}/aliases/available/a.aliases.bash" "${BASH_IT?}/enabled/350---a.aliases.bash" assert_link_exist "${BASH_IT?}/enabled/350---a.aliases.bash" - ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/enabled/150---b.aliases.bash" + run ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/enabled/150---b.aliases.bash" assert_link_exist "${BASH_IT?}/enabled/150---b.aliases.bash" - ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/enabled/250---c.plugin.bash" + run ln -s "${BASH_IT?}/plugins/available/c.plugin.bash" "${BASH_IT?}/enabled/250---c.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/250---c.plugin.bash" # Add one file in the old directory structure - ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" + run ln -s "${BASH_IT?}/aliases/available/b.aliases.bash" "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" assert_link_exist "${BASH_IT?}/aliases/enabled/150---b.aliases.bash" # The `test_alias` alias should not exist run alias test_alias &> /dev/null assert_failure + run ln -s "$BASH_IT/aliases/available/a.aliases.bash" "$BASH_IT/enabled/350---a.aliases.bash" + assert_link_exist "$BASH_IT/enabled/350---a.aliases.bash" + run ln -s "$BASH_IT/aliases/available/b.aliases.bash" "$BASH_IT/enabled/750---b.aliases.bash" + assert_link_exist "$BASH_IT/enabled/750---b.aliases.bash" + run ln -s "$BASH_IT/plugins/available/c.plugin.bash" "$BASH_IT/enabled/250---c.aplugin.bash" + assert_link_exist "$BASH_IT/enabled/250---c.plugin.bash" + # Add one file in the old directory structure + run ln -s "$BASH_IT/aliases/available/b.aliases.bash" "$BASH_IT/aliases/enabled/750---b.aliases.bash" + assert_link_exist "$BASH_IT/aliases/enabled/750---b.aliases.bash" + load "${BASH_IT?}/bash_it.sh" run alias test_alias &> /dev/null @@ -259,11 +324,17 @@ function local_setup_file() { } @test "bash-it: load enabled aliases from new structure, priority-based" { - ln -s "${BASH_IT?}/aliases/available/atom.aliases.bash" "${BASH_IT?}/enabled/150---atom.aliases.bash" + run ln -s "${BASH_IT?}/aliases/available/atom.aliases.bash" "${BASH_IT?}/enabled/150---atom.aliases.bash" assert_link_exist "${BASH_IT?}/enabled/150---atom.aliases.bash" - ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash" + run ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/enabled/250---base.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" + mkdir -p "$BASH_IT/enabled" + run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/enabled/750---atom.aliases.bash" + assert_link_exist "$BASH_IT/enabled/750---atom.aliases.bash" + run ln -s "$BASH_IT/plugins/available/base.plugin.bash" "$BASH_IT/enabled/250---base.plugin.bash" + assert_link_exist "$BASH_IT/enabled/250---base.plugin.bash" + # The `ah` alias should not exist run alias ah &> /dev/null assert_failure @@ -275,11 +346,18 @@ function local_setup_file() { } @test "bash-it: load enabled aliases from old structure, priority-based" { - ln -s "${BASH_IT?}/aliases/available/atom.aliases.bash" "${BASH_IT?}/aliases/enabled/150---atom.aliases.bash" + run ln -s "${BASH_IT?}/aliases/available/atom.aliases.bash" "${BASH_IT?}/aliases/enabled/150---atom.aliases.bash" assert_link_exist "${BASH_IT?}/aliases/enabled/150---atom.aliases.bash" - ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" + run ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" assert_link_exist "${BASH_IT?}/plugins/enabled/250---base.plugin.bash" + mkdir -p "$BASH_IT/aliases/enabled" + mkdir -p "$BASH_IT/plugins/enabled" + run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/750---atom.aliases.bash" + assert_link_exist "$BASH_IT/aliases/enabled/750---atom.aliases.bash" + run ln -s "$BASH_IT/plugins/available/base.plugin.bash" "$BASH_IT/plugins/enabled/250---base.plugin.bash" + assert_link_exist "$BASH_IT/plugins/enabled/250---base.plugin.bash" + # The `ah` alias should not exist run alias ah &> /dev/null assert_failure @@ -291,9 +369,9 @@ function local_setup_file() { } @test "bash-it: load enabled aliases from old structure, without priorities" { - ln -s "${BASH_IT?}/aliases/available/atom.aliases.bash" "${BASH_IT?}/aliases/enabled/atom.aliases.bash" + run ln -s "${BASH_IT?}/aliases/available/atom.aliases.bash" "${BASH_IT?}/aliases/enabled/atom.aliases.bash" assert_link_exist "${BASH_IT?}/aliases/enabled/atom.aliases.bash" - ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/base.plugin.bash" + run ln -s "${BASH_IT?}/plugins/available/base.plugin.bash" "${BASH_IT?}/plugins/enabled/base.plugin.bash" assert_link_exist "${BASH_IT?}/plugins/enabled/base.plugin.bash" # The `ah` alias should not exist diff --git a/test/completion/bash-it.completion.bats b/test/completion/bash-it.completion.bats index 8ee9ef0722..8129366ae2 100644 --- a/test/completion/bash-it.completion.bats +++ b/test/completion/bash-it.completion.bats @@ -169,8 +169,8 @@ function __check_completion() { } @test "completion bash-it: disable - provide the a* aliases when atom is enabled with the old location and priority-based name" { - run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/150---atom.aliases.bash" - assert_link_exist "$BASH_IT/aliases/enabled/150---atom.aliases.bash" + run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/750---atom.aliases.bash" + assert_link_exist "$BASH_IT/aliases/enabled/750---atom.aliases.bash" run ln -s "$BASH_IT/completion/available/apm.completion.bash" "$BASH_IT/completion/enabled/350---apm.completion.bash" assert_link_exist "$BASH_IT/completion/enabled/350---apm.completion.bash" @@ -180,8 +180,8 @@ function __check_completion() { } @test "completion bash-it: disable - provide the a* aliases when atom is enabled with the new location and priority-based name" { - run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/enabled/150---atom.aliases.bash" - assert_link_exist "$BASH_IT/enabled/150---atom.aliases.bash" + run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/enabled/750---atom.aliases.bash" + assert_link_exist "$BASH_IT/enabled/750---atom.aliases.bash" run ln -s "$BASH_IT/completion/available/apm.completion.bash" "$BASH_IT/enabled/350---apm.completion.bash" assert_link_exist "$BASH_IT/enabled/350---apm.completion.bash" @@ -202,8 +202,8 @@ function __check_completion() { } @test "completion bash-it: disable - provide the docker-machine plugin when docker-machine is enabled with the old location and priority-based name" { - run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" - assert_link_exist "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" + run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/750---docker-compose.aliases.bash" + assert_link_exist "$BASH_IT/aliases/enabled/750---docker-compose.aliases.bash" run ln -s "$BASH_IT/plugins/available/docker-machine.plugin.bash" "$BASH_IT/plugins/enabled/350---docker-machine.plugin.bash" assert_link_exist "$BASH_IT/plugins/enabled/350---docker-machine.plugin.bash" @@ -213,8 +213,8 @@ function __check_completion() { } @test "completion bash-it: disable - provide the docker-machine plugin when docker-machine is enabled with the new location and priority-based name" { - run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/enabled/150---docker-compose.aliases.bash" - assert_link_exist "$BASH_IT/enabled/150---docker-compose.aliases.bash" + run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/enabled/750---docker-compose.aliases.bash" + assert_link_exist "$BASH_IT/enabled/750---docker-compose.aliases.bash" run ln -s "$BASH_IT/plugins/available/docker-machine.plugin.bash" "$BASH_IT/enabled/350---docker-machine.plugin.bash" assert_link_exist "$BASH_IT/enabled/350---docker-machine.plugin.bash" @@ -235,8 +235,8 @@ function __check_completion() { } @test "completion bash-it: disable - provide the todo.txt-cli aliases when todo plugin is enabled with the old location and priority-based name" { - run ln -s "$BASH_IT/aliases/available/todo.txt-cli.aliases.bash" "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash" - assert_link_exist "$BASH_IT/aliases/enabled/150---todo.txt-cli.aliases.bash" + run ln -s "$BASH_IT/aliases/available/todo.txt-cli.aliases.bash" "$BASH_IT/aliases/enabled/750---todo.txt-cli.aliases.bash" + assert_link_exist "$BASH_IT/aliases/enabled/750---todo.txt-cli.aliases.bash" run ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/plugins/enabled/350---todo.plugin.bash" assert_link_exist "$BASH_IT/plugins/enabled/350---todo.plugin.bash" @@ -246,8 +246,8 @@ function __check_completion() { } @test "completion bash-it: disable - provide the todo.txt-cli aliases when todo plugin is enabled with the new location and priority-based name" { - run ln -s "$BASH_IT/aliases/available/todo.txt-cli.aliases.bash" "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash" - assert_link_exist "$BASH_IT/enabled/150---todo.txt-cli.aliases.bash" + run ln -s "$BASH_IT/aliases/available/todo.txt-cli.aliases.bash" "$BASH_IT/enabled/750---todo.txt-cli.aliases.bash" + assert_link_exist "$BASH_IT/enabled/750---todo.txt-cli.aliases.bash" run ln -s "$BASH_IT/plugins/available/todo.plugin.bash" "$BASH_IT/enabled/350---todo.plugin.bash" assert_link_exist "$BASH_IT/enabled/350---todo.plugin.bash" @@ -275,16 +275,16 @@ function __check_completion() { } @test "completion bash-it: enable - provide the a* aliases when atom is enabled with the old location and priority-based name" { - run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/150---atom.aliases.bash" - assert_link_exist "$BASH_IT/aliases/enabled/150---atom.aliases.bash" + run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/aliases/enabled/750---atom.aliases.bash" + assert_link_exist "$BASH_IT/aliases/enabled/750---atom.aliases.bash" run __check_completion 'bash-it enable alias a' assert_output "all ag ansible apt" } @test "completion bash-it: enable - provide the a* aliases when atom is enabled with the new location and priority-based name" { - run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/enabled/150---atom.aliases.bash" - assert_link_exist "$BASH_IT/enabled/150---atom.aliases.bash" + run ln -s "$BASH_IT/aliases/available/atom.aliases.bash" "$BASH_IT/enabled/750---atom.aliases.bash" + assert_link_exist "$BASH_IT/enabled/750---atom.aliases.bash" run __check_completion 'bash-it enable alias a' assert_output "all ag ansible apt" @@ -299,16 +299,16 @@ function __check_completion() { } @test "completion bash-it: enable - provide the docker-* plugins when docker-compose is enabled with the old location and priority-based name" { - run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" - assert_link_exist "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" + run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/750---docker-compose.aliases.bash" + assert_link_exist "$BASH_IT/aliases/enabled/750---docker-compose.aliases.bash" run __check_completion 'bash-it enable plugin docker' assert_output "docker docker-compose docker-machine" } @test "completion bash-it: enable - provide the docker-* plugins when docker-compose is enabled with the new location and priority-based name" { - run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/enabled/150---docker-compose.aliases.bash" - assert_link_exist "$BASH_IT/enabled/150---docker-compose.aliases.bash" + run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/enabled/750---docker-compose.aliases.bash" + assert_link_exist "$BASH_IT/enabled/750---docker-compose.aliases.bash" run __check_completion 'bash-it enable plugin docker' assert_output "docker docker-compose docker-machine" @@ -323,16 +323,16 @@ function __check_completion() { } @test "completion bash-it: enable - provide the docker* completions when docker-compose is enabled with the old location and priority-based name" { - run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" - assert_link_exist "$BASH_IT/aliases/enabled/150---docker-compose.aliases.bash" + run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/aliases/enabled/750---docker-compose.aliases.bash" + assert_link_exist "$BASH_IT/aliases/enabled/750---docker-compose.aliases.bash" run __check_completion 'bash-it enable completion docker' assert_output "docker docker-compose docker-machine" } @test "completion bash-it: enable - provide the docker* completions when docker-compose is enabled with the new location and priority-based name" { - run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/enabled/150---docker-compose.aliases.bash" - assert_link_exist "$BASH_IT/enabled/150---docker-compose.aliases.bash" + run ln -s "$BASH_IT/aliases/available/docker-compose.aliases.bash" "$BASH_IT/enabled/750---docker-compose.aliases.bash" + assert_link_exist "$BASH_IT/enabled/750---docker-compose.aliases.bash" run __check_completion 'bash-it enable completion docker' assert_output "docker docker-compose docker-machine" diff --git a/test/install/install.bats b/test/install/install.bats old mode 100644 new mode 100755 index 5288907e8f..c8f5445654 --- 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" { @@ -30,7 +22,7 @@ function local_setup_file() { assert_file_exist "$HOME/$BASH_IT_CONFIG_FILE" - assert_link_exist "${BASH_IT?}/enabled/150---general.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/750---general.aliases.bash" assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/800---aliases.completion.bash" assert_link_exist "${BASH_IT?}/enabled/350---bash-it.completion.bash" diff --git a/test/install/uninstall.bats b/test/install/uninstall.bats index 48ad21623f..ef3c9d157a 100644 --- a/test/install/uninstall.bats +++ b/test/install/uninstall.bats @@ -23,41 +23,82 @@ function local_setup_file() { assert_file_exist "${BASH_IT?}/uninstall.sh" } -@test "uninstall: run the uninstall script with an existing backup file" { +@test "uninstall: run the uninstall script with existing backup 'bashrc'" { local md5_bak md5_conf cd "${BASH_IT?}" - echo "test file content for backup" > "$HOME/$BASH_IT_CONFIG_FILE.bak" - echo "test file content for original file" > "$HOME/$BASH_IT_CONFIG_FILE" - md5_bak=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}') + echo "test file cont BASH_IT_COent for backup" > "${HOME?}/$BASH_IT_CONFIG_FILE.bak" + echo "test file content for original BASH_IT file" > "${HOME?}/$BASH_IT_CONFIG_FILE" + 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" - md5_conf=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}') + 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" { +@test "uninstall: run the uninstall script with existing backup 'bash_profile'" { + local md5_bak md5_conf + BASH_IT_CONFIG_FILE=.bash_profile + + 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" + md5_bak=$(md5sum "${HOME?}/$BASH_IT_CONFIG_FILE.bak" | awk '{print $1}') + + run "${BASH_IT?}/uninstall.sh" + assert_success + + 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" + + 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" { local md5_orig md5_uninstall - cd "${BASH_IT?}" + BASH_IT_CONFIG_FILE=.bashrc + + echo "test file content for original BASH_IT file" > "${HOME?}/$BASH_IT_CONFIG_FILE" + 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" + + 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" { + local md5_orig md5_uninstall + BASH_IT_CONFIG_FILE=.bash_profile + + echo "test file content for original BASH_IT file" > "${HOME?}/$BASH_IT_CONFIG_FILE" + md5_orig=$(md5sum "${HOME?}/$BASH_IT_CONFIG_FILE" | awk '{print $1}') - echo "test file content for original file" > "$HOME/$BASH_IT_CONFIG_FILE" - md5_orig=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE" | awk '{print $1}') + run "${BASH_IT?}/uninstall.sh" - run ./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_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" - md5_uninstall=$(md5sum "$HOME/$BASH_IT_CONFIG_FILE.uninstall" | awk '{print $1}') + md5_uninstall=$(md5sum "${HOME?}/$BASH_IT_CONFIG_FILE.uninstall" | awk '{print $1}') assert_equal "$md5_orig" "$md5_uninstall" } diff --git a/test/plugins/battery.plugin.bats b/test/lib/battery.bats similarity index 99% rename from test/plugins/battery.plugin.bats rename to test/lib/battery.bats index aa4aef5471..3fed46be15 100644 --- a/test/plugins/battery.plugin.bats +++ b/test/lib/battery.bats @@ -4,7 +4,7 @@ load "${MAIN_BASH_IT_DIR?}/test/test_helper.bash" function local_setup_file() { setup_libs "helpers" - load "${BASH_IT?}/plugins/available/battery.plugin.bash" + load "${BASH_IT?}/lib/battery.bash" } # Sets up the `_command_exists` function so that it only responds `true` if called with diff --git a/test/lib/helpers.bats b/test/lib/helpers.bats index 806a0ce8c0..92635c785c 100644 --- a/test/lib/helpers.bats +++ b/test/lib/helpers.bats @@ -40,40 +40,40 @@ function local_setup() { } @test "helpers: bash-it help list aliases with ag aliases enabled" { - ln -s "${BASH_IT?}/aliases/available/ag.aliases.bash" "${BASH_IT?}/aliases/enabled/150---ag.aliases.bash" - assert_link_exist "${BASH_IT?}/aliases/enabled/150---ag.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/ag.aliases.bash" "${BASH_IT?}/aliases/enabled/750---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/750---ag.aliases.bash" - run _help-list-aliases "${BASH_IT?}/aliases/enabled/150---ag.aliases.bash" + run _help-list-aliases "${BASH_IT?}/aliases/enabled/750---ag.aliases.bash" assert_line -n 0 "ag:" } @test "helpers: bash-it help list aliases with todo.txt-cli aliases enabled" { - ln -s "${BASH_IT?}/aliases/available/todo.txt-cli.aliases.bash" "${BASH_IT?}/aliases/enabled/150---todo.txt-cli.aliases.bash" - assert_link_exist "${BASH_IT?}/aliases/enabled/150---todo.txt-cli.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/todo.txt-cli.aliases.bash" "${BASH_IT?}/aliases/enabled/750---todo.txt-cli.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/750---todo.txt-cli.aliases.bash" - run _help-list-aliases "${BASH_IT?}/aliases/enabled/150---todo.txt-cli.aliases.bash" + run _help-list-aliases "${BASH_IT?}/aliases/enabled/750---todo.txt-cli.aliases.bash" assert_line -n 0 "todo.txt-cli:" } @test "helpers: bash-it help list aliases with docker-compose aliases enabled" { - ln -s "${BASH_IT?}/aliases/available/docker-compose.aliases.bash" "${BASH_IT?}/aliases/enabled/150---docker-compose.aliases.bash" - assert_link_exist "${BASH_IT?}/aliases/enabled/150---docker-compose.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/docker-compose.aliases.bash" "${BASH_IT?}/aliases/enabled/750---docker-compose.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/750---docker-compose.aliases.bash" - run _help-list-aliases "${BASH_IT?}/aliases/enabled/150---docker-compose.aliases.bash" + run _help-list-aliases "${BASH_IT?}/aliases/enabled/750---docker-compose.aliases.bash" assert_line -n 0 "docker-compose:" } @test "helpers: bash-it help list aliases with ag aliases enabled in global directory" { - ln -s "${BASH_IT?}/aliases/available/ag.aliases.bash" "${BASH_IT?}/enabled/150---ag.aliases.bash" - assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/ag.aliases.bash" "${BASH_IT?}/enabled/750---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/750---ag.aliases.bash" - run _help-list-aliases "${BASH_IT?}/enabled/150---ag.aliases.bash" + run _help-list-aliases "${BASH_IT?}/enabled/750---ag.aliases.bash" assert_line -n 0 "ag:" } @test "helpers: bash-it help aliases one alias enabled in the old directory" { - ln -s "${BASH_IT?}/aliases/available/ag.aliases.bash" "${BASH_IT?}/aliases/enabled/150---ag.aliases.bash" - assert_link_exist "${BASH_IT?}/aliases/enabled/150---ag.aliases.bash" + ln -s "${BASH_IT?}/aliases/available/ag.aliases.bash" "${BASH_IT?}/aliases/enabled/750---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/aliases/enabled/750---ag.aliases.bash" run bash-it help aliases assert_line -n 0 "ag:" @@ -81,8 +81,8 @@ function local_setup() { @test "helpers: bash-it help aliases one alias enabled in global directory" { run bash-it enable alias "ag" - assert_line -n 0 'ag enabled with priority 150.' - assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" + assert_line -n 0 'ag enabled with priority 750.' + assert_link_exist "${BASH_IT?}/enabled/750---ag.aliases.bash" run bash-it enable plugin "aws" assert_line -n 0 'aws enabled with priority 250.' @@ -95,14 +95,14 @@ function local_setup() { @test "helpers: enable the todo.txt-cli aliases through the bash-it function" { run bash-it enable alias "todo.txt-cli" - assert_line -n 0 'todo.txt-cli enabled with priority 150.' - assert_link_exist "${BASH_IT?}/enabled/150---todo.txt-cli.aliases.bash" + assert_line -n 0 'todo.txt-cli enabled with priority 750.' + assert_link_exist "${BASH_IT?}/enabled/750---todo.txt-cli.aliases.bash" } @test "helpers: enable the curl aliases" { run _enable-alias "curl" - assert_line -n 0 'curl enabled with priority 150.' - assert_link_exist "${BASH_IT?}/enabled/150---curl.aliases.bash" + assert_line -n 0 'curl enabled with priority 750.' + assert_link_exist "${BASH_IT?}/enabled/750---curl.aliases.bash" } @test "helpers: enable the apm completion through the bash-it function" { @@ -247,7 +247,7 @@ function local_setup() { run _bash-it-profile-load "default" assert_success - assert_link_exist "${BASH_IT?}/enabled/150---general.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/750---general.aliases.bash" assert_link_exist "${BASH_IT?}/enabled/250---base.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/800---aliases.completion.bash" assert_link_exist "${BASH_IT?}/enabled/350---bash-it.completion.bash" @@ -315,7 +315,7 @@ function local_setup() { run _bash-it-profile-load "test" assert_success assert_line -n 0 "Trying to parse profile 'test'..." - assert_link_not_exist "${BASH_IT?}/enabled/150---general.aliases.bash" + assert_link_not_exist "${BASH_IT?}/enabled/750---general.aliases.bash" assert_link_not_exist "${BASH_IT?}/enabled/250---base.plugin.bash" assert_link_not_exist "${BASH_IT?}/enabled/800---aliases.completion.bash" assert_link_not_exist "${BASH_IT?}/enabled/350---bash-it.completion.bash" @@ -340,10 +340,10 @@ function local_setup() { run _disable-alias "general" assert_success assert_output "general disabled." - assert_link_not_exist "${BASH_IT?}/enabled/150---general.aliases.bash" + assert_link_not_exist "${BASH_IT?}/enabled/750---general.aliases.bash" run _bash-it-profile-load "test" assert_success - assert_link_exist "${BASH_IT?}/enabled/150---general.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/750---general.aliases.bash" } @test "helpers: profile load corrupted profile file: bad component" { @@ -441,12 +441,12 @@ function local_setup() { run _bash-it-migrate assert_line -n 0 'Migrating alias todo.txt-cli.' assert_line -n 1 'todo.txt-cli disabled.' - assert_line -n 2 'todo.txt-cli enabled with priority 150.' + assert_line -n 2 'todo.txt-cli enabled with priority 750.' assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/250---node.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/250---ssh.plugin.bash" - assert_link_exist "${BASH_IT?}/enabled/150---todo.txt-cli.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/750---todo.txt-cli.aliases.bash" assert [ ! -L "${BASH_IT?}/plugins/enabled/node.plugin.bash" ] assert [ ! -L "${BASH_IT?}/plugins/enabled/nvm.plugin.bash" ] assert [ ! -L "${BASH_IT?}/aliases/enabled/todo.txt-cli.aliases.bash" ] @@ -469,7 +469,7 @@ function local_setup() { assert_link_exist "${BASH_IT?}/enabled/225---nvm.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/250---node.plugin.bash" assert_link_exist "${BASH_IT?}/enabled/250---ssh.plugin.bash" - assert_link_exist "${BASH_IT?}/enabled/150---todo.txt-cli.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/750---todo.txt-cli.aliases.bash" assert [ ! -L "${BASH_IT?}/plugins/enabled/225----node.plugin.bash" ] assert [ ! -L "${BASH_IT?}/plugins/enabled/250----nvm.plugin.bash" ] assert [ ! -L "${BASH_IT?}/aliases/enabled/250----todo.txt-cli.aliases.bash" ] @@ -617,12 +617,12 @@ function __migrate_all_components() { assert_equal "$available" "$enabled" run _enable-alias "ag" - assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/750---ag.aliases.bash" run _disable-plugin "all" enabled2=$(find "${BASH_IT?}/enabled" -name '[0-9]*.plugin.bash' | wc -l | xargs) assert_equal "0" "$enabled2" - assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/750---ag.aliases.bash" } @test "helpers: disable all plugins in the old directory structure" { @@ -637,12 +637,12 @@ function __migrate_all_components() { assert_equal "2" "$enabled" run _enable-alias "ag" - assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/750---ag.aliases.bash" run _disable-plugin "all" enabled2=$(find "${BASH_IT?}/plugins/enabled" -name '*.plugin.bash' | wc -l | xargs) assert_equal "0" "$enabled2" - assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/750---ag.aliases.bash" } @test "helpers: disable all plugins in the old directory structure with priority" { @@ -657,12 +657,12 @@ function __migrate_all_components() { assert_equal "2" "$enabled" run _enable-alias "ag" - assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/750---ag.aliases.bash" run _disable-plugin "all" enabled2=$(find "${BASH_IT?}/plugins/enabled" -name '*.plugin.bash' | wc -l | xargs) assert_equal "0" "$enabled2" - assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/750---ag.aliases.bash" } @test "helpers: disable all plugins without anything enabled" { @@ -671,18 +671,18 @@ function __migrate_all_components() { assert_equal "0" "$enabled" run _enable-alias "ag" - assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/750---ag.aliases.bash" run _disable-plugin "all" enabled2=$(find "${BASH_IT?}/enabled" -name '[0-9]*.plugin.bash' | wc -l | xargs) assert_equal "0" "$enabled2" - assert_link_exist "${BASH_IT?}/enabled/150---ag.aliases.bash" + assert_link_exist "${BASH_IT?}/enabled/750---ag.aliases.bash" } @test "helpers: enable the ansible aliases through the bash-it function" { run bash-it enable alias "ansible" - assert_line -n 0 'ansible enabled with priority 150.' - assert_link_exist "${BASH_IT?}/enabled/150---ansible.aliases.bash" + assert_line -n 0 'ansible enabled with priority 750.' + assert_link_exist "${BASH_IT?}/enabled/750---ansible.aliases.bash" } @test "helpers: describe the nvm plugin without enabling it" { diff --git a/test/lib/utilities.bats b/test/lib/utilities.bats index 66ad579c66..b23c6c7431 100755 --- a/test/lib/utilities.bats +++ b/test/lib/utilities.bats @@ -78,7 +78,7 @@ function local_setup_file() { @test "_bash-it-component-item-is-enabled() - for an enabled/disabled item" { run bash-it enable alias svn - assert_line -n 0 'svn enabled with priority 150.' + assert_line -n 0 'svn enabled with priority 750.' run _bash-it-component-item-is-enabled alias svn assert_success diff --git a/test/plugins/go.plugin.bats b/test/plugins/go.plugin.bats index 69cb8fef61..b0c2bd1035 100644 --- a/test/plugins/go.plugin.bats +++ b/test/plugins/go.plugin.bats @@ -53,7 +53,7 @@ function setup_go_path() { setup_go_path "$BASH_IT/test/fixtures/go/gopath" setup_go_path "$BASH_IT/test/fixtures/go/gopath2" load "${BASH_IT?}/plugins/available/go.plugin.bash" - assert_equal "$(cut -d':' -f1,2 <<< "$PATH")" "$BASH_IT/test/fixtures/go/gopath2/bin:$BASH_IT/test/fixtures/go/gopath/bin" + assert_equal "$(cut -d':' -f1,2 <<< "$PATH")" "$BASH_IT/test/fixtures/go/gopath/bin:$BASH_IT/test/fixtures/go/gopath2/bin" } @test 'plugins go: multiple entries in GOPATH, with space' { @@ -61,7 +61,7 @@ function setup_go_path() { setup_go_path "$BASH_IT/test/fixtures/go/gopath" setup_go_path "$BASH_IT/test/fixtures/go/go path" load "${BASH_IT?}/plugins/available/go.plugin.bash" - assert_equal "$(cut -d':' -f1,2 <<< "$PATH")" "$BASH_IT/test/fixtures/go/go path/bin:$BASH_IT/test/fixtures/go/gopath/bin" + assert_equal "$(cut -d':' -f1,2 <<< "$PATH")" "$BASH_IT/test/fixtures/go/gopath/bin:$BASH_IT/test/fixtures/go/go path/bin" } @test 'plugins go: multiple entries in GOPATH, with escaped space' { diff --git a/test/themes/base.theme.bats b/test/themes/base.theme.bats index 0cf93d6a97..9384de5cda 100644 --- a/test/themes/base.theme.bats +++ b/test/themes/base.theme.bats @@ -12,8 +12,8 @@ function local_setup_file() { assert_failure } -@test 'themes base: battery_percentage should exist if battery plugin loaded' { - load "${BASH_IT?}/plugins/available/battery.plugin.bash" +@test 'themes base: battery_percentage should exist if battery library loaded' { + load "${BASH_IT?}/lib/battery.bash" run type -a battery_percentage &> /dev/null assert_success @@ -28,10 +28,10 @@ function local_setup_file() { assert_output "" } -@test 'themes base: battery_char should exist if battery plugin loaded' { +@test 'themes base: battery_char should exist if battery library loaded' { unset -f battery_char - load "${BASH_IT?}/plugins/available/battery.plugin.bash" + load "${BASH_IT?}/lib/battery.bash" run type -t battery_percentage assert_success assert_line "function" @@ -57,9 +57,9 @@ function local_setup_file() { assert_output "" } -@test 'themes base: battery_charge should exist if battery plugin loaded' { +@test 'themes base: battery_charge should exist if battery library loaded' { unset -f battery_charge - load "${BASH_IT?}/plugins/available/battery.plugin.bash" + load "${BASH_IT?}/lib/battery.bash" load "${BASH_IT?}/themes/base.theme.bash" run type -a battery_charge &> /dev/null diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 6e2e7e0c00..9b34dbb0a8 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -585,21 +585,15 @@ function prompt_char() { } function battery_char() { - # The battery_char function depends on the presence of the battery_percentage function. - if [[ "${THEME_BATTERY_PERCENTAGE_CHECK}" == true ]] && _command_exists battery_percentage; then - echo -ne "${bold_red?}$(battery_percentage)%" + local battery_percentage + battery_percentage="$(battery_percentage)" + if [[ "${THEME_BATTERY_PERCENTAGE_CHECK}" == true ]]; then + echo -e "${bold_red?}${battery_percentage}%" else false fi } -if ! _command_exists battery_charge; then - # if user has installed battery plugin, skip this... - function battery_charge() { - : # no op - } -fi - function aws_profile() { if [[ -n "${AWS_PROFILE:-}" ]]; then echo -ne "${AWS_PROFILE}" diff --git a/themes/demula/demula.theme.bash b/themes/demula/demula.theme.bash index 4bf2e1efd7..8171abea92 100644 --- a/themes/demula/demula.theme.bash +++ b/themes/demula/demula.theme.bash @@ -80,13 +80,6 @@ ${D_BRANCH_COLOR}%b %r ${D_CHANGES_COLOR}%m%u ${D_DEFAULT_COLOR}" fi } -# checks if the plugin is installed before calling battery_charge -safe_battery_charge() { - if _command_exists battery_charge; then - battery_charge - fi -} - # -------------------------------------------------------------- PROMPT OUTPUT prompt() { local LAST_COMMAND_FAILED @@ -98,7 +91,7 @@ prompt() { if [[ "$OSTYPE" = 'linux'* ]]; then PS1="${TITLEBAR}${SAVE_CURSOR}${MOVE_CURSOR_RIGHTMOST}${MOVE_CURSOR_5_LEFT} -$(safe_battery_charge)${RESTORE_CURSOR}\ +$(battery_charge)${RESTORE_CURSOR}\ ${D_USER_COLOR}\u ${D_INTERMEDIATE_COLOR}\ at ${D_MACHINE_COLOR}\h ${D_INTERMEDIATE_COLOR}\ in ${D_DIR_COLOR}\w ${D_INTERMEDIATE_COLOR}\ @@ -114,7 +107,7 @@ in ${D_DIR_COLOR}\w ${D_INTERMEDIATE_COLOR}\ ${LAST_COMMAND_FAILED}\ $(demula_vcprompt)\ $(is_vim_shell)\ -$(safe_battery_charge) +$(battery_charge) ${D_INTERMEDIATE_COLOR}$ ${D_DEFAULT_COLOR}" fi diff --git a/themes/rana/rana.theme.bash b/themes/rana/rana.theme.bash index 163c600936..41b7bba446 100644 --- a/themes/rana/rana.theme.bash +++ b/themes/rana/rana.theme.bash @@ -112,13 +112,6 @@ ${D_BRANCH_COLOR}%b %r ${D_CHANGES_COLOR}%m%u ${D_DEFAULT_COLOR}" fi } -# checks if the plugin is installed before calling battery_charge -safe_battery_charge() { - if _command_exists battery_charge; then - battery_charge - fi -} - prompt_git() { local s='' local branchName='' @@ -183,7 +176,7 @@ prompt() { if [[ "$OSTYPE" == 'linux'* ]]; then PS1="${TITLEBAR} ${SAVE_CURSOR}${MOVE_CURSOR_RIGHTMOST}${MOVE_CURSOR_5_LEFT}\ -$(safe_battery_charge)${RESTORE_CURSOR}\ +$(battery_charge)${RESTORE_CURSOR}\ ${D_USER_COLOR}\u ${D_INTERMEDIATE_COLOR}\ at ${D_MACHINE_COLOR}\h ${D_INTERMEDIATE_COLOR}\ in ${D_DIR_COLOR}\w ${D_INTERMEDIATE_COLOR}\ @@ -201,7 +194,7 @@ $(prompt_git "$D_INTERMEDIATE_COLOR on $D_GIT_COLOR")\ ${LAST_COMMAND_FAILED}\ $(demula_vcprompt)\ $(is_vim_shell)\ -$(safe_battery_charge) +$(battery_charge) ${D_INTERMEDIATE_COLOR}$ ${D_DEFAULT_COLOR}" fi diff --git a/uninstall.sh b/uninstall.sh index 49a816da8c..c59bf932a7 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -1,6 +1,23 @@ #!/usr/bin/env bash -if [ -z "$BASH_IT" ]; then - BASH_IT="$HOME/.bash_it" +# +# 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}" + +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 case $OSTYPE in @@ -14,25 +31,31 @@ esac # overriding CONFIG_FILE: CONFIG_FILE="${BASH_IT_CONFIG_FILE:-"${CONFIG_FILE}"}" +# 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 - echo -e "\033[0;33mBackup file $HOME/$BACKUP_FILE not found.\033[0m" >&2 +if [[ ! -e "${HOME?}/$BACKUP_FILE" ]]; then + 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" + test -w "${HOME?}/$CONFIG_FILE" \ + && mv "${HOME?}/$CONFIG_FILE" "${HOME?}/$CONFIG_FILE.uninstall" \ + && 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" + test -w "${HOME?}/$BACKUP_FILE" \ + && cp -a "${HOME?}/$BACKUP_FILE" "${HOME?}/$CONFIG_FILE" \ + && rm "${HOME?}/$BACKUP_FILE" \ + && 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"