Skip to content

Commit c740059

Browse files
committed
fix(opencode): render generated config cleanly
Made-with: Cursor
1 parent 5a96965 commit c740059

3 files changed

Lines changed: 15 additions & 13 deletions

File tree

home/.chezmoitemplates/opencode-mcp.jsonc.tmpl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
{{- if and $server.enabled $opencodeEnabled $conditionsMatch -}}
2828
{{- if $first }}{{- $first = false }}{{ else }},{{ end }}
2929
"{{ $serverId }}": {
30-
{{- if hasKey $server "local" }}
30+
{{- if hasKey $server "local" -}}
3131
{{- $openCodeCommandName := $server.local.command -}}
3232
{{- $openCodeCommandArgs := list -}}
3333
{{- range $arg := $server.local.args -}}
@@ -40,14 +40,14 @@
4040
{{- end -}}
4141
{{- $openCodeCommandArgs = append $openCodeCommandArgs $resolvedArg -}}
4242
{{- end -}}
43-
{{- $openCodeCommand := prepend $openCodeCommandArgs $openCodeCommandName -}}
44-
"type": "local",
45-
"command": {{ $openCodeCommand | toPrettyJson " " }},
43+
{{- $openCodeCommand := prepend $openCodeCommandArgs $openCodeCommandName }}
44+
"type": {{ "local" | toJson }},
45+
"command": {{ $openCodeCommand | toPrettyJson | indent 6 | trim }},
4646
{{- else if hasKey $server "remote" }}
47-
"type": "remote",
48-
"url": "{{ $server.remote.url }}",
47+
"type": {{ "remote" | toJson }},
48+
"url": {{ $server.remote.url | toJson }},
4949
{{- end }}
50-
"enabled": {{ $server.enabled | toPrettyJson }}
50+
"enabled": {{ $server.enabled | toJson }}
5151
}
5252
{{- end -}}
5353
{{- end }}

home/.chezmoitemplates/opencode-permission.tmpl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
{{- end -}}
4545

4646
{{- if and $conditionsMatch (eq $rule.kind $kindName) -}}
47+
{{- $pattern := replace "{{ .chezmoi.homeDir }}" $.chezmoi.homeDir $rule.pattern -}}
4748
{{- $supportsMatchMode := false -}}
4849
{{- if hasKey $kindCfg "supportsMatchMode" -}}
4950
{{- $supportsMatchMode = $kindCfg.supportsMatchMode -}}
@@ -64,15 +65,15 @@
6465

6566
{{- if or (eq $matchMode "exact") (eq $matchMode "exactAndWithArgs") -}}
6667
{{- if $firstEntry }}{{- $firstEntry = false }}{{ else }},{{ end }}
67-
"{{ $rule.pattern }}": "{{ $rule.op }}"
68+
{{ $pattern | toJson }}: {{ $rule.op | toJson }}
6869
{{- end -}}
6970
{{- if or (eq $matchMode "withArgs") (eq $matchMode "exactAndWithArgs") -}}
7071
{{- if $firstEntry }}{{- $firstEntry = false }}{{ else }},{{ end }}
71-
"{{ $rule.pattern }}{{ $wildcardSuffix }}": "{{ $rule.op }}"
72+
{{ printf "%s%s" $pattern $wildcardSuffix | toJson }}: {{ $rule.op | toJson }}
7273
{{- end -}}
7374
{{- else -}}
7475
{{- if $firstEntry }}{{- $firstEntry = false }}{{ else }},{{ end }}
75-
"{{ $rule.pattern }}": "{{ $rule.op }}"
76+
{{ $pattern | toJson }}: {{ $rule.op | toJson }}
7677
{{- end -}}
7778
{{- end -}}
7879
{{- end }}
@@ -96,7 +97,8 @@
9697
{{- $kindCfg = index $kinds $rule.kind -}}
9798
{{- end -}}
9899
{{- if and $conditionsMatch (eq (default "" (index $kindCfg "destinationType")) "top_level") -}}
100+
{{- $pattern := replace "{{ .chezmoi.homeDir }}" $.chezmoi.homeDir $rule.pattern -}}
99101
{{- if $firstField }}{{- $firstField = false }}{{ else }},{{ end }}
100-
"{{ $rule.pattern }}": "{{ $rule.op }}"
102+
{{ $pattern | toJson }}: {{ $rule.op | toJson }}
101103
{{- end -}}
102104
{{- end }}

home/dot_config/opencode/opencode.jsonc.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"model": "github-copilot/claude-sonnet-4.6",
88

99
"permission": {
10-
{{- includeTemplate ".chezmoitemplates/opencode-permission.tmpl" . }}
10+
{{- includeTemplate ".chezmoitemplates/opencode-permission.tmpl" . | trimSuffix "\n" }}
1111
},
1212

1313
"plugin": [
@@ -16,6 +16,6 @@
1616
],
1717

1818
"mcp": {
19-
{{- includeTemplate ".chezmoitemplates/opencode-mcp.jsonc.tmpl" . }}
19+
{{- includeTemplate ".chezmoitemplates/opencode-mcp.jsonc.tmpl" . | trimSuffix "\n" }}
2020
}
2121
}

0 commit comments

Comments
 (0)