Skip to content

Commit 60114c9

Browse files
committed
fix: $HOME replacement still necessary
1 parent 0569e70 commit 60114c9

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

common/os_filesystem.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type OsFilesystem struct{}
1212

1313
func (*OsFilesystem) GetAbsolutePath(path string) string {
1414
// homedir is assumed to work correctly
15+
path = FixHomeExpansion(path)
1516
path = ConvertSimpleVarsToBraces(path)
1617
expandedPath, err := homedir.Expand(path)
1718
if err == nil {

common/variable_expander.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
)
1111

1212
func CustomExpandVariables(input string, fn func(key string) (value string, ok bool)) string {
13+
input = FixHomeExpansion(input)
1314
input = ConvertSimpleVarsToBraces(input)
1415
input = strings.TrimSpace(input)
1516
input = strings.Trim(input, fmt.Sprintf("%v\"'", os.PathListSeparator))
@@ -23,3 +24,9 @@ func ConvertSimpleVarsToBraces(input string) string {
2324
return fmt.Sprintf(`${%s}`, parts[1])
2425
})
2526
}
27+
28+
func FixHomeExpansion(path string) string {
29+
path = strings.ReplaceAll(path, "$HOME/", "~/")
30+
path = strings.ReplaceAll(path, "${HOME}/", "~/")
31+
return path
32+
}

0 commit comments

Comments
 (0)