diff --git a/config/config.go b/config/config.go index 75a4e4d9..b03c89d5 100644 --- a/config/config.go +++ b/config/config.go @@ -12,6 +12,7 @@ import ( "log" "net/url" "os" + "os/user" "path/filepath" gap "github.com/muesli/go-app-paths" @@ -84,6 +85,24 @@ func (c *Config) SetURL(u string) error { return err } + // Expand tilde to the users home directory + // This is needed in case the shell is unable to expand the path to the users + // home directory for inputs like these: + // crypto://password@~/path/to/config + // NOTE: - url.Parse() will interpret `~` as the Host Element of the URL in + // this case. + // - Using filepath.Abs() won't work as it will interpret `~` as the + // name of a regular folder. + if url.Host == "~" { + usr, err := user.Current() + if err != nil { + return err + } + + url.Path = filepath.Join(usr.HomeDir, url.Path) + url.Host = "" + } + c.url = url return nil }