From dd10be79e28564b84d0fef0598437baafc79677a Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Wed, 30 Jan 2013 22:29:05 +1300 Subject: [PATCH] Re-wrap functions as functions. Fixes issue with RVM reload (cd wrapper will be overwritten without error) --- lib/git/shell_shortcuts.sh | 4 ++-- test/lib/git/shell_shortcuts_test.sh | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/git/shell_shortcuts.sh b/lib/git/shell_shortcuts.sh index 8026f0b..690bf93 100644 --- a/lib/git/shell_shortcuts.sh +++ b/lib/git/shell_shortcuts.sh @@ -60,8 +60,8 @@ if [ "$shell_command_wrapping_enabled" = "true" ] || [ "$bash_command_wrapping_e eval "$(declare -f $cmd | sed -E "s/^$cmd \(\)/__original_$cmd ()/")" # Remove function unset -f $cmd - # Create wrapped alias for old function - alias "$cmd"="exec_scmb_expand_args __original_$cmd";; + # Create function that wraps old function + eval "${cmd}(){ exec_scmb_expand_args __original_${cmd} \"\$@\"; }";; *'is a shell builtin'*) if [ "${scmbDebug:-}" = "true" ]; then echo "SCMB: $cmd is a shell builtin"; fi diff --git a/test/lib/git/shell_shortcuts_test.sh b/test/lib/git/shell_shortcuts_test.sh index fe17eb9..3a6843a 100755 --- a/test/lib/git/shell_shortcuts_test.sh +++ b/test/lib/git/shell_shortcuts_test.sh @@ -63,7 +63,8 @@ test_shell_command_wrapping() { assertAliasEquals "exec_scmb_expand_args /bin/sed" "sed" assertAliasEquals "exec_scmb_expand_args /bin/cat" "cat" assertAliasEquals "exec_scmb_expand_args builtin cd" "cd" - assertAliasEquals "exec_scmb_expand_args __original_ln" "ln" + assertIncludes "$(declare -f ln)" "ln ()" + assertIncludes "$(declare -f ln)" "exec_scmb_expand_args __original_ln" } test_ls_with_file_shortcuts() {