From e5da83665a79ab9b2b253f7fba8d005f4917d969 Mon Sep 17 00:00:00 2001 From: "Tom \"Ravi\" Hale" Date: Fri, 14 Sep 2018 19:29:06 +0700 Subject: [PATCH] bin_path(): use builtin commands and avoid `which` --- lib/git/aliases.sh | 2 +- lib/git/helpers.sh | 9 ++++++++- lib/git/shell_shortcuts.sh | 2 +- test/lib/git/shell_shortcuts_test.sh | 7 ------- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/git/aliases.sh b/lib/git/aliases.sh index e9c8f59..b7b3f84 100644 --- a/lib/git/aliases.sh +++ b/lib/git/aliases.sh @@ -17,7 +17,7 @@ unalias git > /dev/null 2>&1 unset -f git > /dev/null 2>&1 # Use the full path to git to avoid infinite loop with git function -export _git_cmd="$(\which git)" +export _git_cmd="$(bin_path git)" # Wrap git with the 'hub' github wrapper, if installed (https://github.com/defunkt/hub) if type hub > /dev/null 2>&1; then export _git_cmd="hub"; fi diff --git a/lib/git/helpers.sh b/lib/git/helpers.sh index f2d4107..785bd60 100644 --- a/lib/git/helpers.sh +++ b/lib/git/helpers.sh @@ -13,4 +13,11 @@ function fail_if_not_git_repo() { return 1 fi return 0 -} \ No newline at end of file +} + +bin_path() { + if [[ -n ${ZSH_VERSION:-} ]]; + then builtin whence -cp "$1" 2> /dev/null + else builtin type -P "$1" + fi +} diff --git a/lib/git/shell_shortcuts.sh b/lib/git/shell_shortcuts.sh index c41d6d0..03348a1 100644 --- a/lib/git/shell_shortcuts.sh +++ b/lib/git/shell_shortcuts.sh @@ -108,7 +108,7 @@ fi # Function wrapper around 'll' # Adds numbered shortcuts to output of ls -l, just like 'git status' -if [ "$shell_ls_aliases_enabled" = "true" ] && which ruby > /dev/null 2>&1; then +if [ "$shell_ls_aliases_enabled" = "true" ] && builtin command -v ruby > /dev/null 2>&1; then unalias ll > /dev/null 2>&1; unset -f ll > /dev/null 2>&1 function ls_with_file_shortcuts { local ll_output diff --git a/test/lib/git/shell_shortcuts_test.sh b/test/lib/git/shell_shortcuts_test.sh index 7f1f6f4..6e470a7 100755 --- a/test/lib/git/shell_shortcuts_test.sh +++ b/test/lib/git/shell_shortcuts_test.sh @@ -21,13 +21,6 @@ fi source "$scmbDir/test/support/test_helper.sh" source "$scmbDir/lib/scm_breeze.sh" -bin_path() { - if [ -n "${ZSH_VERSION:-}" ]; - then where "$@" | tail -1 - else which "$@" - fi -} - # Setup #----------------------------------------------------------------------------- oneTimeSetUp() {