From e82e69f1d9684fb4245a46eae1e399ed3122ca52 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Thu, 26 Jan 2012 10:01:33 +0800 Subject: [PATCH] Replaced 1..3 range syntax with 1-3 (Inspired by holygeek's git-number project - https://github.com/holygeek/git-number) --- lib/git/status_shortcuts.sh | 22 +++++----------------- test/lib/git/status_shortcuts_test.sh | 6 +++--- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/lib/git/status_shortcuts.sh b/lib/git/status_shortcuts.sh index fed3b35..4b7bbcb 100644 --- a/lib/git/status_shortcuts.sh +++ b/lib/git/status_shortcuts.sh @@ -145,27 +145,15 @@ git_expand_args() { first=1 for arg in "$@"; do if [[ "$arg" =~ ^[0-9]+$ ]] ; then # Substitute $e{*} variables for any integers - if [ "$first" -eq 1 ]; then - first=0 - else - echo -n " " - fi + if [ "$first" -eq 1 ]; then first=0; else echo -n " "; fi eval printf '%s' "\$$git_env_char$arg" - elif [[ "$arg" =~ ^[0-9]+\.\.[0-9]+$ ]]; then # Expand ranges into $e{*} variables - for i in $(eval echo {$arg}); do - if [ "$first" -eq 1 ]; then - first=0 - else - echo -n " " - fi + elif [[ "$arg" =~ ^[0-9]+-[0-9]+$ ]]; then # Expand ranges into $e{*} variables + for i in $(eval echo {${arg/-/..}}); do + if [ "$first" -eq 1 ]; then first=0; else echo -n " "; fi eval printf '%s' "\$$git_env_char$i" done else # Otherwise, treat $arg as a normal string. - if [ "$first" -eq 1 ]; then - first=0 - else - echo -n " " - fi + if [ "$first" -eq 1 ]; then first=0; else echo -n " "; fi printf '%q' "$arg" fi done diff --git a/test/lib/git/status_shortcuts_test.sh b/test/lib/git/status_shortcuts_test.sh index 7d35973..b79ea8c 100755 --- a/test/lib/git/status_shortcuts_test.sh +++ b/test/lib/git/status_shortcuts_test.sh @@ -51,8 +51,8 @@ test_git_expand_args() { 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" assertEquals "$error" "one three seven" "$(git_expand_args 1 3 7)" - assertEquals "$error" "one two three six" "$(git_expand_args 1..3 6)" - assertEquals "$error" "seven two three four five one" "$(git_expand_args seven 2..5 1)" + assertEquals "$error" "one two three six" "$(git_expand_args 1-3 6)" + assertEquals "$error" "seven two three four five one" "$(git_expand_args seven 2-5 1)" # Test that any args with spaces remain quoted assertEquals "$error" "-m Test\ Commit\ Message one" "$(git_expand_args -m "Test Commit Message" 1)" @@ -218,7 +218,7 @@ test_git_add_shortcuts() { touch a b c d e f g h i j # Show git status, which sets up env variables git_status_shortcuts > /dev/null - git_add_shortcuts 2..4 7 8 > /dev/null + git_add_shortcuts 2-4 7 8 > /dev/null git_status=$(git_status_shortcuts 1 | strip_colors) for c in b c d g h; do