summaryrefslogtreecommitdiff
path: root/git-log-describe.awk
diff options
context:
space:
mode:
authorPeter Wu <lekensteyn@gmail.com>2013-11-22 19:44:08 +0100
committerPeter Wu <lekensteyn@gmail.com>2013-11-22 19:44:08 +0100
commitb696923617e79a6af0360805b993a20fec2f86dc (patch)
tree404f1d7023f344c197adfe86ee56b1a7aef17a44 /git-log-describe.awk
parent849dfcf50db6a9f48e4e665d6450f5e7d1efb3f6 (diff)
downloadscripts-b696923617e79a6af0360805b993a20fec2f86dc.tar.gz
git-log-describe: add git-describe output to git-log
As of today (2013-11-22) there is still no support for adding an indication of tag to the output of git log. This script post-processes the output of `git log` and adds the output of `git describe --first-parent` to line following the commit ID. For a version suitable for `git log --oneline`, see [1]. [1]: http://stackoverflow.com/q/17379010/427545
Diffstat (limited to 'git-log-describe.awk')
-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");
+}