Fixed SCM Breeze command wrapping for %w(vim cat rm cp mv ln ls)

This commit is contained in:
Nathan Broadbent
2012-08-15 21:07:35 +12:00
parent eab3957a11
commit 49c613ceaa

View File

@@ -178,16 +178,43 @@ if [[ "$git_keyboard_shortcuts_enabled" = "true" ]]; then
esac esac
fi fi
# Bash command wrapping # Wrap common commands with numeric argument expansion.
# (Works fine with RVM's cd() wrapper) # Prepends everything with exec_git_expand_args,
#~ if [[ "$bash_command_wrapping_enabled" = "true" ]]; then # even if commands are already aliases or functions
#~ for cmd in vim cat cd rm cp mv ln; do if [[ "$bash_command_wrapping_enabled" = "true" ]]; then
#~ alias $cmd="exec_git_expand_args $cmd" # Do it in a function so we don't bleed variables
#~ done function _git_wrap_commands() {
#~ # Define 'whence' for bash, to get the value of an alias
#~ if [[ "$(type ls)" =~ "--color=auto" ]]; then type whence > /dev/null 2>&1 || function whence() { type "$@" | sed -e "s/.*is aliased to \`//" -e "s/'$//"; }
#~ alias ls="exec_git_expand_args ls --color=auto" local cmd=''
#~ else for cmd in vim cat rm cp mv ln ls; do
#~ alias ls="exec_git_expand_args ls" case "$(type $cmd 2>&1)" in
#~ fi *'exec_git_expand_args'*|*'not found'*);; # Don't do anything if command not found, or already aliased.
#~ fi
*'is aliased to'*|*'is an alias for'*)
# Store original alias
local original_alias="$(whence $cmd)"
# Remove alias, so that which can return binary
unalias $cmd
# Expand original command into full path, to avoid infinite loops
local expanded_alias="$(echo $original_alias | sed "s%^$cmd%$(\which $cmd)%")"
# Command is already an alias
alias $cmd="exec_git_expand_args $expanded_alias";;
*'is a'*'function'*)
# Copy old function into new name
eval "$(declare -f $cmd | sed "s/^$cmd ()/__original_$cmd ()/")"
# Remove function
unset -f $cmd
# Create wrapped alias for old function
alias "$cmd"="exec_git_expand_args __original_$cmd";;
*) # Otherwise, command is a regular script or binary that can be aliased
alias $cmd="exec_git_expand_args $(\which $cmd)";;
esac
done
# Clean up
declare -f whence > /dev/null && unset -f whence
}
_git_wrap_commands
fi