summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xgit-log-describe.awk34
1 files changed, 34 insertions, 0 deletions
diff --git a/git-log-describe.awk b/git-log-describe.awk
new file mode 100755
index 0000000..0ac233e
--- /dev/null
+++ b/git-log-describe.awk
@@ -0,0 +1,34 @@
+#!/usr/bin/awk -f
+# Adds a "git describe" (nearest tag) output for `git log` (with support for
+# color escapes and --graph markers). --oneline is not supported.
+#
+# Copyright (c) 2013 Peter Wu <lekensteyn@gmail.com>
+# Licensed under GPLv3 or any latter version
+
+function has_color(str) {
+ if (str ~ /\033/) return 1;
+
+ return 0;
+}
+
+{ print; }
+
+{
+ is_color = has_color($0);
+ # strip color escapes for easier text matching
+ gsub(/\033\[[0-9]*m/, "");
+
+ text_len = length($0);
+ # remove --graph markers
+ sub(/^[*|][*|_/\\ ]*/, "");
+ indent_len = length($0) - text_len;
+}
+
+$1 == "commit" && $2 ~ /^[0-9a-f]{5,40}$/ {
+ hash = $2;
+
+ printf("%" indent_len "sDescribe: ", "");
+ if (is_color) printf("\033[96m"); # light cyan
+ system("git describe --first-parent " hash);# " |tr -d '\''\n'\''");
+ if (is_color) printf("\033[m");
+}