gott is a go toml transformer. It adds support for go templates in toml files with table-local and global scope (and some selection sugar – dashed and numeric indexes are allowed!). It also bundles the sprig template functions.
# example.toml
[font]
family = "Triplicate"
size = 12
# references can be local, or global
config = "{{.family}} {{.size}}"
[loud]
font-config = "{{.font.config | upper}}"
[loud-copy]
# use the '-' key for splicing other tables into this one.
# with this, you could reference the following path: '.loud-copy.font-config'
- = [ "loud" ]
Usage of gott:
-t string
Add a toml file to consider
-T string
Add raw toml to consider
-n string
Narrow the namespaces to consider
-p string
Promote a namespace to the top level
-o string
Output type <shell|toml|keys>
-q string
query a value (formatted render: '{{.%s}}')
-R string
Render a string
-r file
Render a file
-v be verbose
# $ gott -t example.toml -o toml
[font]
config = 'Triplicate 12'
family = 'Triplicate'
size = 12
[loud]
font-config = 'TRIPLICATE 12'
$ gott -t example.toml -o shell
font_config='Triplicate 12'
font_family='Triplicate'
font_size='12'
loud_font_config='TRIPLICATE 12'
Let’s add another toml file:
# colors.toml
[colors]
solarized = [
"#eee8d5", "#dc322f", "#859900", "#b58900", "#268bd2", "#d33682", "#2aa198", "#eee8d5",
"#fdf6e3", "#cb4b16", "#93a1a1", "#839496", "#839496", "#6c71c4", "#93a1a1", "#fdf6e3"
]
$ cat xresources.template
URxvt.font: xft:{{.font.family}}:size={{.font.size}}
{{range $i, $color := .colors.solarized}}
*.color{{$i}}: {{$color}}
{{- end}}
$ gott -t colors.toml -t example.toml -r xresources.template
URxvt.font: xft:Triplicate:size=12
*.color0: #eee8d5
*.color1: #dc322f
*.color2: #859900
*.color3: #b58900
*.color4: #268bd2
*.color5: #d33682
*.color6: #2aa198
*.color7: #eee8d5
*.color8: #fdf6e3
*.color9: #cb4b16
*.color10: #93a1a1
*.color11: #839496
*.color12: #839496
*.color13: #6c71c4
*.color14: #93a1a1
*.color15: #fdf6e3
This project exists so I can learn some go. The initial incarnation was written on a train with no internet, where I scrounged through go doc
like a caveman. My default dynamic+functional style does not translate well to go, there has been some head banging. The idea of gott
is somewhat dynamic in itself, so might be a bad problem for go. Oh well.
People who helped through feedback and iteration:
Previous inspo: https://github.com/metakirby5/zenbu