Replaced 1..3 range syntax with 1-3 (Inspired by holygeek's git-number project - https://github.com/holygeek/git-number)

This commit is contained in:
Nathan Broadbent
2012-01-26 10:01:33 +08:00
parent e22ec216cb
commit e82e69f1d9
2 changed files with 8 additions and 20 deletions

View File

@@ -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

View File

@@ -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