Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
c.out
codecov.out
coverage
coverage.out
dist/
is
18 changes: 12 additions & 6 deletions known.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ import (
)

const (
manpath = "MANPATH"
path = "PATH"
trueStr = "true"
falseStr = "false"
manpath = "MANPATH"
path = "PATH"
xdgConfigDirs = "XDG_CONFIG_DIRS"
xdgDataDirs = "XDG_DATA_DIRS"
trueStr = "true"
falseStr = "false"
)

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

func shouldSplitEnvVar(name string) bool {
return name == path || name == manpath || name == xdgConfigDirs || name == xdgDataDirs
}

func envSummary(ctx *types.Context, asJSON bool, asMarkdown bool) error {
envMap := make(map[string]any)
rows := make([][]string, 0, len(os.Environ()))
Expand All @@ -325,7 +331,7 @@ func envSummary(ctx *types.Context, asJSON bool, asMarkdown bool) error {

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

if name == path || name == manpath {
if shouldSplitEnvVar(name) {
pathParts := strings.Split(value, ":")
if asJSON {
envMap[name] = pathParts
Expand Down Expand Up @@ -369,7 +375,7 @@ func getEnv(ctx *types.Context, name string, asJSON bool) (string, error) {
values := []string{}

switch {
case set && (name == path || name == manpath):
case set && shouldSplitEnvVar(name):
values = strings.Split(value, ":")
case set:
values = append(values, value)
Expand Down