diff --git a/common/os_filesystem.go b/common/os_filesystem.go index 755de09..5f75b11 100644 --- a/common/os_filesystem.go +++ b/common/os_filesystem.go @@ -12,6 +12,7 @@ type OsFilesystem struct{} func (*OsFilesystem) GetAbsolutePath(path string) string { // homedir is assumed to work correctly + path = FixHomeExpansion(path) path = ConvertSimpleVarsToBraces(path) expandedPath, err := homedir.Expand(path) if err == nil { diff --git a/common/variable_expander.go b/common/variable_expander.go index 662e84b..1dbb980 100644 --- a/common/variable_expander.go +++ b/common/variable_expander.go @@ -10,6 +10,7 @@ import ( ) func CustomExpandVariables(input string, fn func(key string) (value string, ok bool)) string { + input = FixHomeExpansion(input) input = ConvertSimpleVarsToBraces(input) input = strings.TrimSpace(input) input = strings.Trim(input, fmt.Sprintf("%v\"'", os.PathListSeparator)) @@ -23,3 +24,9 @@ func ConvertSimpleVarsToBraces(input string) string { return fmt.Sprintf(`${%s}`, parts[1]) }) } + +func FixHomeExpansion(path string) string { + path = strings.ReplaceAll(path, "$HOME/", "~/") + path = strings.ReplaceAll(path, "${HOME}/", "~/") + return path +}