Skip to content
Browse files

Provide X-compatible find_binary function that finds a binary for a g…

…iven command. Works with zsh/bash
  • Loading branch information...
1 parent c46e165 commit 0a797fb6206e5e83e0e0839dc305f38c55e42159 @ndbroadbent committed
Showing with 14 additions and 10 deletions.
  1. +5 −5 lib/git/shell_shortcuts.sh
  2. +9 −5 lib/scm_breeze.sh
View
10 lib/git/shell_shortcuts.sh
@@ -29,15 +29,15 @@ if [ "$shell_command_wrapping_enabled" = "true" ] || [ "$bash_command_wrapping_e
if [ "${scmbDebug:-}" = "true" ]; then echo "SCMB: $cmd is an alias"; fi
# Store original alias
local original_alias="$(whence $cmd)"
- # Remove alias, so that which can return binary
+ # Remove alias, so that we can find binary
unalias $cmd
# Detect original $cmd type, and escape
case "$(type $cmd 2>&1)" in
# Escape shell builtins with 'builtin'
*'is a shell builtin'*) local escaped_cmd="builtin $cmd";;
- # Get full path for files with 'which'
- *) local escaped_cmd="$(\which $cmd)";;
+ # Get full path for files with 'find_binary' function
+ *) local escaped_cmd="$(find_binary $cmd)";;
esac
# Expand original command into full path, to avoid infinite loops
@@ -62,8 +62,8 @@ if [ "$shell_command_wrapping_enabled" = "true" ] || [ "$bash_command_wrapping_e
*)
if [ "${scmbDebug:-}" = "true" ]; then echo "SCMB: $cmd is an executable file"; fi
# Otherwise, command is a regular script or binary,
- # and the full path can be found from 'which'
- alias $cmd="exec_scmb_expand_args $(\which $cmd)";;
+ # and the full path can be found with 'find_binary' function
+ alias $cmd="exec_scmb_expand_args $(find_binary $cmd)";;
esac
done
# Clean up
View
14 lib/scm_breeze.sh
@@ -12,11 +12,15 @@ disable_nullglob() { if [ $shell = "zsh" ]; then unsetopt NULL_GLOB; else shopt
# Alias wrapper that ignores errors if alias is not defined.
_alias(){ alias "$@" 2> /dev/null; }
-if [ $shell = "zsh" ]; then
- export GIT_BINARY=$(type -p git | sed 's/git is //' | head -1)
-else
- export GIT_BINARY=$(type -P git)
-fi
+find_binary(){
+ if [ $shell = "zsh" ]; then
+ type -p "$1" | sed "s/$1 is //" | head -1
+ else
+ type -P "$1"
+ fi
+}
+
+export GIT_BINARY=$(find_binary git)
# Updates SCM Breeze from GitHub.
update_scm_breeze() {

0 comments on commit 0a797fb

Please sign in to comment.
Something went wrong with that request. Please try again.