Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions pkg/files/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,30 @@ func GetSSHPrivateKeyPath(home string) string {
return fpath
}

// GetUserSSHConfigPath returns the user's SSH config path.
// The path can be overridden via the BREV_SSH_CONFIG_FILE environment variable.
func expandPathWithHome(path, home string) string {
if path == "" {
return path
}

if path[0] == '~' {
// Only expand the current user's home directory, i.e. paths starting with "~" or "~/".
if len(path) == 1 || path[1] == '/' || path[1] == os.PathSeparator {
// Strip the "~" and join the remainder with the provided home directory.
return filepath.Join(home, path[1:])
}
}

return path
}

func GetUserSSHConfigPath(home string) (string, error) {
if override := os.Getenv("BREV_SSH_CONFIG_FILE"); override != "" {
expanded := expandPathWithHome(override, home)
cleaned := filepath.Clean(expanded)
return cleaned, nil
}
sshConfigPath := filepath.Join(home, ".ssh", "config")
return sshConfigPath, nil
}
Expand Down
Loading