lib/helpers: cleanup

- Improve `pushd`/`popd` somewhat
- local some parameters
- Lose weird Mac-specific alternate shell startup file (Bash loads startup files on Mac the same as it does on any other *nix system.)
pull/1904/head
John D Pell 2021-10-12 10:27:29 -07:00
parent 7ea6efab3f
commit 9c0415c41e
1 changed files with 20 additions and 30 deletions

View File

@ -252,9 +252,8 @@ function _bash-it_update_migrate_and_restart() {
_bash-it-migrate _bash-it-migrate
echo "" echo ""
echo "All done, enjoy!" echo "All done, enjoy!"
# Don't forget to restore the original pwd! # Don't forget to restore the original pwd (called from `_bash-it-update-`)!
# shellcheck disable=SC2164 popd > /dev/null || return
popd &> /dev/null
_bash-it-restart _bash-it-restart
else else
echo "Error updating Bash-it, please, check if your Bash-it installation folder (${BASH_IT}) is clean." echo "Error updating Bash-it, please, check if your Bash-it installation folder (${BASH_IT}) is clean."
@ -297,8 +296,7 @@ function _bash-it-update-() {
if [[ -z "$TARGET" ]]; then if [[ -z "$TARGET" ]]; then
echo "Can not find tags, so can not update to latest stable version..." echo "Can not find tags, so can not update to latest stable version..."
# shellcheck disable=SC2164 popd > /dev/null || return
popd &> /dev/null
return return
fi fi
else else
@ -361,8 +359,7 @@ function _bash-it-update-() {
echo "Bash-it is up to date, nothing to do!" echo "Bash-it is up to date, nothing to do!"
fi fi
fi fi
# shellcheck disable=SC2164 popd > /dev/null || return
popd &> /dev/null
} }
function _bash-it-migrate() { function _bash-it-migrate() {
@ -408,7 +405,7 @@ function _bash-it-version() {
_about 'shows current Bash-it version' _about 'shows current Bash-it version'
_group 'lib' _group 'lib'
cd "${BASH_IT}" || return pushd "${BASH_IT?}" > /dev/null || return
if [[ -z "${BASH_IT_REMOTE:-}" ]]; then if [[ -z "${BASH_IT_REMOTE:-}" ]]; then
BASH_IT_REMOTE="origin" BASH_IT_REMOTE="origin"
@ -439,7 +436,7 @@ function _bash-it-version() {
echo "Compare to latest: $BASH_IT_GIT_URL/compare/$TARGET...master" echo "Compare to latest: $BASH_IT_GIT_URL/compare/$TARGET...master"
cd - &> /dev/null || return popd > /dev/null || return
} }
function _bash-it-doctor() { function _bash-it-doctor() {
@ -486,14 +483,11 @@ function _bash-it-restart() {
saved_pwd="${PWD}" saved_pwd="${PWD}"
case $OSTYPE in if shopt -q login_shell; then
darwin*) init_file=.bash_profile
init_file=.bash_profile else
;; init_file=.bashrc
*) fi
init_file=.bashrc
;;
esac
exec "${0/-/}" --rcfile <(echo "source \"$HOME/$init_file\"; cd \"$saved_pwd\"") exec "${0/-/}" --rcfile <(echo "source \"$HOME/$init_file\"; cd \"$saved_pwd\"")
} }
@ -503,19 +497,15 @@ function _bash-it-reload() {
pushd "${BASH_IT?}" > /dev/null || return pushd "${BASH_IT?}" > /dev/null || return
case $OSTYPE in # shellcheck disable=SC1090
darwin*) if shopt -q login_shell; then
# shellcheck disable=SC1090 # shellcheck source-path=$HOME
source ~/.bash_profile source ~/.bash_profile
;; else
*) # shellcheck source-path=$HOME
# shellcheck disable=SC1090 source ~/.bashrc
source ~/.bashrc fi
;; popd > /dev/null || return
esac
# shellcheck disable=SC2164
popd
} }
function _bash-it-describe() { function _bash-it-describe() {