Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand tilde to the users home directory #139

Merged
merged 1 commit into from
Aug 21, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"log"
"net/url"
"os"
"os/user"
"path/filepath"

gap "github.com/muesli/go-app-paths"
Expand Down Expand Up @@ -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)
penguwin marked this conversation as resolved.
Show resolved Hide resolved
url.Host = ""
}

c.url = url
return nil
}
Expand Down