/
prelude.go
77 lines (67 loc) · 1.46 KB
/
prelude.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Package prelude contains the most commonly used utility functions
package prelude
import (
"text/template"
"github.com/Masterminds/sprig"
)
var sprigIgnore = map[string]struct{}{
"reverse": {},
"toJson": {},
"toPrettyJson": {},
"toRawJson": {},
"toString": {},
"typeOf": {},
}
func FuncMap() template.FuncMap {
out := template.FuncMap{
"cat": Cat,
"cd": CD,
"echo": Echo,
"exec": Exec,
"exit": Exit,
"fzf": FZF,
"glob": Glob,
"head": Head,
"ls": Ls,
"make": Make,
"mkdir": Mkdir,
"printf": Printf,
"pwd": PWD,
"reverse": Reverse,
"sort": Sort,
"stdin": Stdin,
"tail": Tail,
"tee": Tee,
"toGo": ToGo,
"toJSON": ToJSON,
"toPrettyJSON": ToPrettyJSON,
"toPrettyXML": ToPrettyXML,
"toShell": ToShell,
"toString": ToString,
"toStringSlice": ToStringSlice,
"toTOML": ToTOML,
"toXML": ToXML,
"toYAML": ToYAML,
"touch": Touch,
"typeOf": TypeOf,
}
for name, fn := range sprig.TxtFuncMap() {
if _, ok := sprigIgnore[name]; ok {
continue
}
out[name] = fn
}
return out
}
type File struct {
filename string
}
func (f File) String() string {
return f.filename
}
type Directory struct {
dirname string
}
func (d Directory) String() string {
return d.dirname
}