Skip to content

Commit

Permalink
fix: $HOME replacement still necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
d-led committed Dec 31, 2023
1 parent 0569e70 commit 60114c9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions common/os_filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions common/variable_expander.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
}

0 comments on commit 60114c9

Please sign in to comment.