Skip to content

Commit 1444d00

Browse files
Update pkg/files/files.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent d21aad9 commit 1444d00

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

pkg/files/files.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,27 @@ func GetSSHPrivateKeyPath(home string) string {
7575

7676
// GetUserSSHConfigPath returns the user's SSH config path.
7777
// The path can be overridden via the BREV_SSH_CONFIG_FILE environment variable.
78+
func expandPathWithHome(path, home string) string {
79+
if path == "" {
80+
return path
81+
}
82+
83+
if path[0] == '~' {
84+
// Only expand the current user's home directory, i.e. paths starting with "~" or "~/".
85+
if len(path) == 1 || path[1] == '/' || path[1] == os.PathSeparator {
86+
// Strip the "~" and join the remainder with the provided home directory.
87+
return filepath.Join(home, path[1:])
88+
}
89+
}
90+
91+
return path
92+
}
93+
7894
func GetUserSSHConfigPath(home string) (string, error) {
7995
if override := os.Getenv("BREV_SSH_CONFIG_FILE"); override != "" {
80-
return override, nil
96+
expanded := expandPathWithHome(override, home)
97+
cleaned := filepath.Clean(expanded)
98+
return cleaned, nil
8199
}
82100
sshConfigPath := filepath.Join(home, ".ssh", "config")
83101
return sshConfigPath, nil

0 commit comments

Comments
 (0)