diff --git a/config/config.go b/config/config.go index 7933a5e3..c1761db5 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,23 @@ 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() on it 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) + } + c.url = url return nil }