Created
March 20, 2011 17:13
-
-
Save sbellware/878463 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function changes { | |
start="$1" | |
end="$2" | |
if [ -z "$2" ]; then | |
start="$1"^ | |
end="$1" | |
fi | |
if [ -z "$1" ]; then | |
start=HEAD^ | |
end=HEAD | |
fi | |
git diff --name-only $start..$end | sort | uniq | |
} |
okay, I realize I cleaned up the shell stuff. . . but goofed on the actual task at hand. . . I changed the semantics of the program entirely by not reading into the ^ stuff carefully. I'll post a fix in a moment.
I came to the conclusion that your if-then logic is readable relative to any fancy shell parameter expansion I can come up with (which I gave up on). I think you have what you need to figure it out now.
For future reference I recommend the Advance Bash Scripting Guide - PDF / HTML versions at http://tldp.org/guides.html
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Couldn't figure out how gist works. . . so I'll just post my code inline:
There's a number of things I'm illustrating in this commit.
Learning POSIX-compliant shell is a sometimes tedious, because the specification is kind of hidden away by The Open Group. I often end up looking at the Dash manpage , because Dash more or less targets POSIX specifically. Other shells like Bash and Korn layer tiers of functionality above and beyond the POSIX specification, which just makes for non-portable shell scripts. And furthermore, these extensions aren't worth it. They're great to help out users interactively, but they're generally not worth the tradeoff for portability. If you really need features beyond POSIX-compliant shell. . . just jump to Ruby. You're probably looking for things like real data structures. Messing around with things like Bash arrays is a waste.