From 5958eae1c8295557fcfbf5a4369b2b925c42b4fe Mon Sep 17 00:00:00 2001
From: Adar Nimrod <nimrod@shore.co.il>
Date: Sun, 9 Oct 2016 07:11:37 +0300
Subject: [PATCH] Added username template function.

---
 pkg/template/functions.go | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/pkg/template/functions.go b/pkg/template/functions.go
index a81e96f..452f6f6 100644
--- a/pkg/template/functions.go
+++ b/pkg/template/functions.go
@@ -8,6 +8,7 @@ import (
 	"strings"
 	"text/template"
 	"time"
+	"os/user"
 )
 
 var (
@@ -22,6 +23,7 @@ var (
 		"env":      os.Getenv,
 		"time":     CurrentTimeInFmt,
 		"hostname": func() string { return os.Getenv("HOSTNAME") },
+		"username": UserName,
 
 		"toBinary": func(s string) string {
 			n, err := strconv.Atoi(s)
@@ -100,3 +102,13 @@ func CurrentTimeInFmt(fmt string) string {
 
 	return t.Format(fmt)
 }
+
+
+// UserName returns the user's name (not the login name).
+func UserName() string {
+    t, err := user.Current();
+    if ( err != nil ) {
+        return "Unknown";
+    }
+    return t.Name;
+}
-- 
GitLab