feat: support ~ (tilde) expansion in match_dirs paths
This commit is contained in:
parent
c293e233d2
commit
ac780231a8
2 changed files with 66 additions and 0 deletions
|
|
@ -151,6 +151,8 @@ func (c *Config) ResolveHostByPath(cwd string) string {
|
|||
if dir == "" {
|
||||
continue
|
||||
}
|
||||
// Expand ~ to home directory
|
||||
dir = expandHome(dir)
|
||||
// Resolve symlinks in the configured dir as well
|
||||
if resolved, err := filepath.EvalSymlinks(dir); err == nil {
|
||||
dir = resolved
|
||||
|
|
@ -173,6 +175,18 @@ func (c *Config) ResolveHostByPath(cwd string) string {
|
|||
return bestHost
|
||||
}
|
||||
|
||||
// expandHome replaces a leading ~ with the user's home directory.
|
||||
func expandHome(path string) string {
|
||||
if path == "~" || strings.HasPrefix(path, "~/") {
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return path
|
||||
}
|
||||
return filepath.Join(home, path[1:])
|
||||
}
|
||||
return path
|
||||
}
|
||||
|
||||
func (c *Config) SetHost(hostname string, host HostConfig) {
|
||||
if c.Hosts == nil {
|
||||
c.Hosts = make(map[string]HostConfig)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue