Skip to content

Commit c49492b

Browse files
oaldersclaude
andcommitted
Add XDG_CONFIG_DIRS and XDG_DATA_DIRS to split environment variables
These XDG variables contain colon-separated paths similar to PATH and MANPATH. Split them on ':' and display each path on a separate line for better readability in table output. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 600e5b0 commit c49492b

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

known.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ import (
2525
)
2626

2727
const (
28-
manpath = "MANPATH"
29-
path = "PATH"
30-
trueStr = "true"
31-
falseStr = "false"
28+
manpath = "MANPATH"
29+
path = "PATH"
30+
xdgConfigDirs = "XDG_CONFIG_DIRS"
31+
xdgDataDirs = "XDG_DATA_DIRS"
32+
trueStr = "true"
33+
falseStr = "false"
3234
)
3335

3436
// Run "is known ...".
@@ -310,6 +312,10 @@ func batterySummary(ctx *types.Context, nth int, asJSON bool, asMarkdown bool) (
310312
return tabular(headers, rows, asMarkdown), nil
311313
}
312314

315+
func shouldSplitEnvVar(name string) bool {
316+
return name == path || name == manpath || name == xdgConfigDirs || name == xdgDataDirs
317+
}
318+
313319
func envSummary(ctx *types.Context, asJSON bool, asMarkdown bool) error {
314320
envMap := make(map[string]any)
315321
rows := make([][]string, 0, len(os.Environ()))
@@ -325,7 +331,7 @@ func envSummary(ctx *types.Context, asJSON bool, asMarkdown bool) error {
325331

326332
name, value := parts[0], parts[1]
327333

328-
if name == path || name == manpath {
334+
if shouldSplitEnvVar(name) {
329335
pathParts := strings.Split(value, ":")
330336
if asJSON {
331337
envMap[name] = pathParts
@@ -369,7 +375,7 @@ func getEnv(ctx *types.Context, name string, asJSON bool) (string, error) {
369375
values := []string{}
370376

371377
switch {
372-
case set && (name == path || name == manpath):
378+
case set && shouldSplitEnvVar(name):
373379
values = strings.Split(value, ":")
374380
case set:
375381
values = append(values, value)

0 commit comments

Comments
 (0)