Can you use hashes in templates?
Environment
- Mac OSX
- dotter 0.13.2
The question
I currently use freshrc and am converting to dotter.
Probably a simple question, but I haven't had much luck finding an answer. Is there a way to have a hash/dictionary in a template?
I currently have this file which has aliases stored as a hash in ruby erb, which then generates one version for zsh (which uses aliases) and one version for fish (which uses abbr)
I'm wondering if there's a way in a template to do something similar to this pseudo-code.
aliases = {
git: {
g: 'git',
gs: 'git status'
},
navigation: {
bp: 'bat --plain',
rmf: 'rm -rf',
md: 'mkdir -p'
}
}
for set in aliases {
for alias, command in set {
if (abbr_language == true)
"abbr {alias} {command}"
else
"alias {alias} {command}"
\if
}
}
Should be possible. To do nested tables like that in TOML, you should do something like
[mypackage.variables.aliases.git]
g = "git"
gs = "git status"
[mypackage.variables.aliases.navigation]
bp = "bat --plain`
...
Although I'm not sure why you're breaking it into sets in the first place - you could probably just have all under aliases
In the rc file, according to this handlebars documentation: https://handlebarsjs.com/guide/builtin-helpers.html#each You could use something like
{{#each aliases}}
abbr {{@key}} {{this}}
{{/each}}