From 6bd6690d80931062210d18f3e9855074707b03a8 Mon Sep 17 00:00:00 2001 From: Reto Brunner Date: Sat, 2 May 2020 14:06:02 +0200 Subject: [PATCH] templates: add version func Fixes #316 --- aerc.go | 4 ++++ doc/aerc-templates.7.scd | 7 +++++++ lib/templates/template.go | 8 ++++++++ 3 files changed, 19 insertions(+) diff --git a/aerc.go b/aerc.go index 1b51d6d..12d9453 100644 --- a/aerc.go +++ b/aerc.go @@ -19,6 +19,7 @@ import ( "git.sr.ht/~sircmpwn/aerc/commands/terminal" "git.sr.ht/~sircmpwn/aerc/config" "git.sr.ht/~sircmpwn/aerc/lib" + "git.sr.ht/~sircmpwn/aerc/lib/templates" libui "git.sr.ht/~sircmpwn/aerc/lib/ui" "git.sr.ht/~sircmpwn/aerc/widgets" ) @@ -179,6 +180,9 @@ func main() { as.OnMailto = aerc.Mailto } + // set the aerc version so that we can use it in the template funcs + templates.SetVersion(Version) + close(initDone) for !ui.ShouldExit() { diff --git a/doc/aerc-templates.7.scd b/doc/aerc-templates.7.scd index ff5d4b5..d065012 100644 --- a/doc/aerc-templates.7.scd +++ b/doc/aerc-templates.7.scd @@ -125,6 +125,13 @@ aerc provides the following additional functions: {{dateFormat .Date "Mon Jan 2 15:04:05 -0700 MST 2006"}} ``` +*version* + Returns the version of aerc, which can be useful for things like X-Mailer. + + ``` + X-Mailer: aerc {{version}} + ``` + *Function chaining* All of the template functions can be chained together if needed. diff --git a/lib/templates/template.go b/lib/templates/template.go index e18328c..d16ac1f 100644 --- a/lib/templates/template.go +++ b/lib/templates/template.go @@ -16,6 +16,13 @@ import ( "github.com/mitchellh/go-homedir" ) +var version string + +//SetVersion initializes the aerc version displayed in template functions +func SetVersion(v string) { + version = v +} + type TemplateData struct { To []*mail.Address Cc []*mail.Address @@ -168,6 +175,7 @@ var templateFuncs = template.FuncMap{ "dateFormat": time.Time.Format, "toLocal": toLocal, "exec": cmd, + "version": func() string { return version }, } func findTemplate(templateName string, templateDirs []string) (string, error) {