Skip to content

Commit 46f33b2

Browse files
committed
expand '~' to home in config file path
1 parent 28dcc52 commit 46f33b2

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

‎config/config.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ func Expand(path, env, home string) string {
116116
path = env
117117
}
118118

119+
if path != "" && path[0] == '~' {
120+
path = strings.Replace(path, "~/", fmt.Sprintf("%s/", home), 1)
121+
}
122+
119123
if path == "" {
120124
path = filepath.Join(home, File)
121125
}

‎config/config_test.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ func TestExpandConfigPath(t *testing.T) {
5353
"",
5454
"path/to/config.json",
5555
},
56+
{
57+
"",
58+
"~/config.json",
59+
"/home/alice/config.json",
60+
},
5661
{
5762
"",
5863
"",

0 commit comments

Comments
 (0)