git_expand_args => scmb_expand_args

This commit is contained in:
Nathan Broadbent
2012-08-15 21:10:46 +12:00
parent b0d6b0e8b2
commit accbcc5957
5 changed files with 19 additions and 19 deletions

View File

@@ -67,7 +67,7 @@ $ gco 5
``` ```
You can use these shortcuts with system commands by passing your command through `exec_git_expand_args` You can use these shortcuts with system commands by passing your command through `exec_scmb_expand_args`
(default alias is 'ge'): (default alias is 'ge'):

View File

@@ -36,7 +36,7 @@ git_status_shortcuts_alias="gs"
git_add_shortcuts_alias="ga" git_add_shortcuts_alias="ga"
git_add_patch_alias="gap" git_add_patch_alias="gap"
git_show_files_alias="gsf" git_show_files_alias="gsf"
exec_git_expand_args_alias="ge" exec_scmb_expand_args_alias="ge"
# 2. Commands that handle paths (with shortcut args expanded) # 2. Commands that handle paths (with shortcut args expanded)
git_checkout_alias="gco" git_checkout_alias="gco"
git_checkout_branch_alias="gcob" git_checkout_branch_alias="gcob"

View File

@@ -22,7 +22,7 @@ function git(){
# Only expand args for a subset of git commands # Only expand args for a subset of git commands
case $1 in case $1 in
checkout|commit|reset|rm|blame|diff|add|log) checkout|commit|reset|rm|blame|diff|add|log)
exec_git_expand_args "$_git_cmd" "$@";; exec_scmb_expand_args "$_git_cmd" "$@";;
*) *)
"$_git_cmd" "$@";; "$_git_cmd" "$@";;
esac esac
@@ -68,7 +68,7 @@ __git_alias () {
# SCM Breeze functions # SCM Breeze functions
_alias $git_status_shortcuts_alias="git_status_shortcuts" _alias $git_status_shortcuts_alias="git_status_shortcuts"
_alias $git_add_shortcuts_alias="git_add_shortcuts" _alias $git_add_shortcuts_alias="git_add_shortcuts"
_alias $exec_git_expand_args_alias="exec_git_expand_args" _alias $exec_scmb_expand_args_alias="exec_scmb_expand_args"
_alias $git_show_files_alias="git_show_affected_files" _alias $git_show_files_alias="git_show_affected_files"
_alias $git_commit_all_alias='git_commit_all' _alias $git_commit_all_alias='git_commit_all'
@@ -179,7 +179,7 @@ if [[ "$git_keyboard_shortcuts_enabled" = "true" ]]; then
fi fi
# Wrap common commands with numeric argument expansion. # Wrap common commands with numeric argument expansion.
# Prepends everything with exec_git_expand_args, # Prepends everything with exec_scmb_expand_args,
# even if commands are already aliases or functions # even if commands are already aliases or functions
if [[ "$bash_command_wrapping_enabled" = "true" ]]; then if [[ "$bash_command_wrapping_enabled" = "true" ]]; then
# Do it in a function so we don't bleed variables # Do it in a function so we don't bleed variables
@@ -189,7 +189,7 @@ if [[ "$bash_command_wrapping_enabled" = "true" ]]; then
local cmd='' local cmd=''
for cmd in vim emacs gedit cat rm cp mv ln ls; do for cmd in vim emacs gedit cat rm cp mv ln ls; do
case "$(type $cmd 2>&1)" in case "$(type $cmd 2>&1)" in
*'exec_git_expand_args'*|*'not found'*);; # Don't do anything if command not found, or already aliased. *'exec_scmb_expand_args'*|*'not found'*);; # Don't do anything if command not found, or already aliased.
*'is aliased to'*|*'is an alias for'*) *'is aliased to'*|*'is an alias for'*)
# Store original alias # Store original alias
@@ -199,7 +199,7 @@ if [[ "$bash_command_wrapping_enabled" = "true" ]]; then
# Expand original command into full path, to avoid infinite loops # Expand original command into full path, to avoid infinite loops
local expanded_alias="$(echo $original_alias | sed "s%^$cmd%$(\which $cmd)%")" local expanded_alias="$(echo $original_alias | sed "s%^$cmd%$(\which $cmd)%")"
# Command is already an alias # Command is already an alias
alias $cmd="exec_git_expand_args $expanded_alias";; alias $cmd="exec_scmb_expand_args $expanded_alias";;
*'is a'*'function'*) *'is a'*'function'*)
# Copy old function into new name # Copy old function into new name
@@ -207,10 +207,10 @@ if [[ "$bash_command_wrapping_enabled" = "true" ]]; then
# Remove function # Remove function
unset -f $cmd unset -f $cmd
# Create wrapped alias for old function # Create wrapped alias for old function
alias "$cmd"="exec_git_expand_args __original_$cmd";; alias "$cmd"="exec_scmb_expand_args __original_$cmd";;
*) # Otherwise, command is a regular script or binary that can be aliased *) # Otherwise, command is a regular script or binary that can be aliased
alias $cmd="exec_git_expand_args $(\which $cmd)";; alias $cmd="exec_scmb_expand_args $(\which $cmd)";;
esac esac
done done
# Clean up # Clean up

View File

@@ -79,7 +79,7 @@ git_silent_add_shortcuts() {
if [ -n "$1" ]; then if [ -n "$1" ]; then
# Expand args and process resulting set of files. # Expand args and process resulting set of files.
IFS=$'\t' IFS=$'\t'
for file in $(git_expand_args "$@"); do for file in $(scmb_expand_args "$@"); do
# Use 'git rm' if file doesn't exist and 'ga_auto_remove' is enabled. # Use 'git rm' if file doesn't exist and 'ga_auto_remove' is enabled.
if [[ $ga_auto_remove == "yes" ]] && ! [ -e "$file" ]; then if [[ $ga_auto_remove == "yes" ]] && ! [ -e "$file" ]; then
echo -n "# " echo -n "# "
@@ -112,7 +112,7 @@ git_show_affected_files(){
# Numbered shortcut variables are produced by various commands, such as: # Numbered shortcut variables are produced by various commands, such as:
# * git_status_shortcuts() - git status implementation # * git_status_shortcuts() - git status implementation
# * git_show_affected_files() - shows files affected by a given SHA1, etc. # * git_show_affected_files() - shows files affected by a given SHA1, etc.
git_expand_args() { scmb_expand_args() {
first=1 first=1
OLDIFS="$IFS"; IFS=" " # We need to split on spaces to loop over expanded range OLDIFS="$IFS"; IFS=" " # We need to split on spaces to loop over expanded range
for arg in "$@"; do for arg in "$@"; do
@@ -135,7 +135,7 @@ git_expand_args() {
# Execute a command with expanded args, e.g. Delete files 6 to 12: $ ge rm 6-12 # Execute a command with expanded args, e.g. Delete files 6 to 12: $ ge rm 6-12
# Fails if command is a number or range (probably not worth fixing) # Fails if command is a number or range (probably not worth fixing)
exec_git_expand_args() { eval "$(git_expand_args "$@" | sed -e 's/\([][()<>^ ]\)/\\\1/g')"; } exec_scmb_expand_args() { eval "$(scmb_expand_args "$@" | sed -e 's/\([][()<>^ ]\)/\\\1/g')"; }
# Clear numbered env variables # Clear numbered env variables
git_clear_vars() { git_clear_vars() {
@@ -152,7 +152,7 @@ _git_resolve_merge_conflict() {
if [ -n "$2" ]; then if [ -n "$2" ]; then
# Expand args and process resulting set of files. # Expand args and process resulting set of files.
IFS=$'\t' IFS=$'\t'
for file in $(git_expand_args "${@:2}"); do for file in $(scmb_expand_args "${@:2}"); do
git checkout "--$1""s" "$file" # "--$1""s" is expanded to --ours or --theirs git checkout "--$1""s" "$file" # "--$1""s" is expanded to --ours or --theirs
git add "$file" git add "$file"
echo -e "# Added $1 version of '$file'" echo -e "# Added $1 version of '$file'"

View File

@@ -47,17 +47,17 @@ setupTestRepo() {
# Unit tests # Unit tests
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
test_git_expand_args() { test_scmb_expand_args() {
local e1="one"; local e2="two"; local e3="three"; local e4="four"; local e5="five"; local e6="six"; local e7="seven" local e1="one"; local e2="two"; local e3="three"; local e4="four"; local e5="five"; local e6="six"; local e7="seven"
local error="Args not expanded correctly" local error="Args not expanded correctly"
assertEquals "$error" "$(printf 'one\tthree\tseven')" "$(git_expand_args 1 3 7)" assertEquals "$error" "$(printf 'one\tthree\tseven')" "$(scmb_expand_args 1 3 7)"
assertEquals "$error" "$(printf 'one\ttwo\tthree\tsix')" "$(git_expand_args 1-3 6)" assertEquals "$error" "$(printf 'one\ttwo\tthree\tsix')" "$(scmb_expand_args 1-3 6)"
assertEquals "$error" "$(printf 'seven\ttwo\tthree\tfour\tfive\tone')" "$(git_expand_args seven 2-5 1)" assertEquals "$error" "$(printf 'seven\ttwo\tthree\tfour\tfive\tone')" "$(scmb_expand_args seven 2-5 1)"
# Test that any args with spaces remain quoted # Test that any args with spaces remain quoted
assertEquals "$error" "$(printf -- '-m\tTest Commit Message\tone')" "$(git_expand_args -m "Test Commit Message" 1)" assertEquals "$error" "$(printf -- '-m\tTest Commit Message\tone')" "$(scmb_expand_args -m "Test Commit Message" 1)"
assertEquals "$error" "$(printf -- '-ma\tTest Commit Message\tUnquoted')"\ assertEquals "$error" "$(printf -- '-ma\tTest Commit Message\tUnquoted')"\
"$(git_expand_args -ma "Test Commit Message" "Unquoted")" "$(scmb_expand_args -ma "Test Commit Message" "Unquoted")"
} }