Provide X-compatible find_binary function that finds a binary for a given command. Works with zsh/bash
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user