File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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+
7894func 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
You can’t perform that action at this time.
0 commit comments