]> git.donarmstrong.com Git - bin.git/commitdiff
add git shortrev
authorDon Armstrong <don@donarmstrong.com>
Tue, 14 May 2013 17:50:34 +0000 (10:50 -0700)
committerDon Armstrong <don@donarmstrong.com>
Tue, 14 May 2013 17:50:34 +0000 (10:50 -0700)
git-shortrev [new file with mode: 0755]

diff --git a/git-shortrev b/git-shortrev
new file mode 100755 (executable)
index 0000000..9af7e4b
--- /dev/null
@@ -0,0 +1,19 @@
+#!/bin/bash
+
+_usage() {
+    echo "Usage: git shortrev <committish>" 1>&2
+    exit 1
+}
+
+_shortrev() {
+    commit="${1:-HEAD}"
+    name="$(git name-rev --name-only "$commit")";
+    rev="$(git rev-parse --short "$commit")";
+    echo "$name@$rev";
+}
+
+case $# in
+    1 ) _shortrev "$1";;
+    0 ) _shortrev;;
+    * ) _usage
+esac