From 17fc1bb69b41f3bccc4d045b63e3c6b5c1000e84 Mon Sep 17 00:00:00 2001 From: ishandhanani Date: Mon, 23 Feb 2026 11:12:19 -0800 Subject: [PATCH 1/3] feat(ssh): support BREV_SSH_CONFIG_FILE env var override Allow users to specify a custom SSH config file path via the BREV_SSH_CONFIG_FILE environment variable. When set, brev commands (refresh, etc.) will edit the specified file instead of ~/.ssh/config. This is useful for nix-managed systems where the main SSH config is read-only. --- pkg/files/files.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/files/files.go b/pkg/files/files.go index 0b1796e7..bff4cc94 100644 --- a/pkg/files/files.go +++ b/pkg/files/files.go @@ -74,6 +74,9 @@ func GetSSHPrivateKeyPath(home string) string { } func GetUserSSHConfigPath(home string) (string, error) { + if override := os.Getenv("BREV_SSH_CONFIG_FILE"); override != "" { + return override, nil + } sshConfigPath := filepath.Join(home, ".ssh", "config") return sshConfigPath, nil } From d21aad9136f8a1b0e0fc429fa1dc6660256954a5 Mon Sep 17 00:00:00 2001 From: ishandhanani <82981111+ishandhanani@users.noreply.github.com> Date: Mon, 23 Feb 2026 16:54:05 -0800 Subject: [PATCH 2/3] Update pkg/files/files.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- pkg/files/files.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/files/files.go b/pkg/files/files.go index bff4cc94..89f995eb 100644 --- a/pkg/files/files.go +++ b/pkg/files/files.go @@ -73,6 +73,8 @@ 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 GetUserSSHConfigPath(home string) (string, error) { if override := os.Getenv("BREV_SSH_CONFIG_FILE"); override != "" { return override, nil From 1444d004a0ba72ce300d31b61420a343b7ec0514 Mon Sep 17 00:00:00 2001 From: ishandhanani <82981111+ishandhanani@users.noreply.github.com> Date: Mon, 23 Feb 2026 16:54:25 -0800 Subject: [PATCH 3/3] Update pkg/files/files.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- pkg/files/files.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/pkg/files/files.go b/pkg/files/files.go index 89f995eb..e375f11d 100644 --- a/pkg/files/files.go +++ b/pkg/files/files.go @@ -75,9 +75,27 @@ func GetSSHPrivateKeyPath(home string) string { // 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 != "" { - return override, nil + expanded := expandPathWithHome(override, home) + cleaned := filepath.Clean(expanded) + return cleaned, nil } sshConfigPath := filepath.Join(home, ".ssh", "config") return sshConfigPath, nil