Add dynamic context update and prompt for missing values

main
jri 8 months ago
parent b423a72171
commit 38acebea6f

@ -1,7 +1,9 @@
modal = true modal = true
default_flags = "gh" default_flags = "gh"
show_selection_mark = true show_selection_mark = true
{{#if ctx.icons}}
icon_theme = "vscode" icon_theme = "vscode"
{{/if}}
[special-paths] [special-paths]
"**/.git" = "hide" "**/.git" = "hide"

@ -11,11 +11,7 @@ config.font = wezterm.font_with_fallback {
'Jetbrains Mono', 'Jetbrains Mono',
'Broot Icons Visual Studio Code', 'Broot Icons Visual Studio Code',
} }
{{#if (eq system.hostname "deepthought")}} config.font_size = {{ctx.font-size}}
config.font_size = 12
{{else}}
config.font_size = 10
{{/if}}
config.color_scheme = 'Dracula' config.color_scheme = 'Dracula'
config.window_background_gradient = { config.window_background_gradient = {
orientation = 'Vertical', orientation = 'Vertical',

@ -53,6 +53,52 @@
[push] [push]
autoSetupRemote = true autoSetupRemote = true
{{else}} {{else}}
{{#if (eq ctx.environment "unitb")}}
[user]
email = julius.riegel@unitb.de
name = jri
[credential]
helper = store
[filter "lfs"]
process = git-lfs filter-process
required = true
clean = git-lfs clean -- %f
smudge = git-lfs smudge -- %f
[alias]
c = commit -s
commit = commit -s
[core]
editor = helix
pager = delta
[interactive]
diffFilter = delta --color-only
[add.interactive]
useBuiltin = false # required for git 2.37.0
[delta]
navigate = true # use n and N to move between diff sections
light = false # set to true if you're in a terminal w/ a light background color (e.g. the default macOS terminal)
[merge]
conflictstyle = diff3
tool = vimdiff
[diff]
colorMoved = default
rebase = false
[init]
defaultBranch = main
[mergetool]
prompt = false
[pull]
rebase = false
[gpg]
program = /home/jri/.local/share/scripts/gpg-pinentry-loopback.bash
[push]
autoSetupRemote = true
{{else}}
[user] [user]
email = trivernis@protonmail.com email = trivernis@protonmail.com
name = trivernis name = trivernis
@ -107,3 +153,4 @@
[push] [push]
autoSetupRemote = true autoSetupRemote = true
{{/if}} {{/if}}
{{/if}}

@ -0,0 +1,54 @@
def before_apply_all [ctx] {
let silo_ctx = (silo context | from json)
let config_file = ($silo_ctx.dirs.config | path join "silo.toml")
mut config = open-config $config_file
$config.template_context = ($config.template_context
| apply-defaults
| default {}
| merge (template-context $ctx $silo_ctx $config)
)
print $"Context updated to ($config.template_context)"
$config | save -f $config_file
}
def open-config [path: string] {
if ($path | path exists) {
open $path
} else {
{}
}
}
def template-context [ctx: any, silo_ctx: any, config: any] {
{
username: (whoami)
}
}
def apply-defaults [] {
let cfg = $in
{
system-id: ($cfg | get-or-prompt system-id)
environment: ($cfg | get-or-prompt environment)
font-size: 12
icons: false
}
}
def get-or-prompt [key: string] {
$in | get -i $key | default-prompt $"Enter `($key)`: "
}
def default-prompt [prompt: string] {
default-with {|| input $prompt}
}
def default-with [fn] {
if $in == null {
do $fn
} else {
$in
}
}

@ -1,23 +0,0 @@
def before_apply_all [ctx] {
let silo_ctx = (silo context | from json)
let config_file = ($silo_ctx.dirs.config | path join "silo.toml")
mut config = open_config $config_file
$config.template_context = ($config.template_context | default {} | merge (template_context $ctx $silo_ctx $config))
$config | save -f $config_file
}
def open_config [path: string] {
if ($path | path exists) {
open $path
} else {
{}
}
}
def template_context [ctx: any, silo_ctx: any, config: any] {
{
username: (whoami)
}
}
Loading…
Cancel
Save