-
Notifications
You must be signed in to change notification settings - Fork 4
Templates
You can find out how to create Go templates in the official documentation or in the various places on the internet.
A couple of examples:
-
returning a variable called
item
defined in a context. Its value is "foo":{{ .item }}
will evaluate tofoo
-
running a function to generate string with two
item
s next to each other{{ printf "%s%s" .item }}
-
returning the first item in a list called
lst
{{ index .lst 0 }}
-
returning the value under key
foo
from a mapsomeMap
{{ index .someMap "foo" }}
Native Go template functions are very limited so fzshell also provides useful functions from the sprig project.
Additionally, the following functions are available:
The cmd
function evaluates a single command (without creating a subshell).
{{ .cmd "echo" "foo" .item }}
Returns "foo bar" if item == "bar"
.
Similarly to cmd
, but for commands that accept only stdin
input. Like tr
:
{{ .item | cmdPipe "tr" "o" "a" }}
Returns "faa" if item == "foo"
.
Concatenates arguments and evaluates them in bash
:
{{ .shell "echo " .item "a" " b" }}
produces "fooa b" if item == "foo"
.
Convenience function to get a value from a list in a chained call. Its troublesome
to do with the native index
function.
{{ .lst | listGet 0 }}
Convenience function to get a value from a map in a chained call. Its troublesome
to do with the native index
function.
{{ .foomap | mapGet "barKey" }}