feat: ProxyCommand support (#26)

* Add base for ProxyCommand

* Fix crashes with ProxyCommand

* Add ProxyCommand to README

---------

Co-authored-by: Simon Gaufreteau <sgaufret@amazon.lu>
This commit is contained in:
Simon Gaufreteau
2026-01-04 17:49:04 +01:00
committed by GitHub
parent 825c534ebe
commit ce9d678652
6 changed files with 87 additions and 32 deletions

View File

@@ -19,6 +19,7 @@ type SSHHost struct {
Port string
Identity string
ProxyJump string
ProxyCommand string
Options string
RemoteCommand string // Command to execute after SSH connection
RequestTTY string // Request TTY (yes, no, force, auto)
@@ -328,6 +329,10 @@ func parseSSHConfigFileWithProcessedFiles(configPath string, processedFiles map[
if currentHost != nil {
currentHost.ProxyJump = value
}
case "proxycommand":
if currentHost != nil {
currentHost.ProxyCommand = value
}
case "remotecommand":
if currentHost != nil {
currentHost.RemoteCommand = value
@@ -613,6 +618,13 @@ func AddSSHHostToFile(host SSHHost, configPath string) error {
}
}
if host.ProxyCommand != "" {
_, err = file.WriteString(fmt.Sprintf(" ProxyCommand=%s\n", host.ProxyCommand))
if err != nil {
return err
}
}
if host.RemoteCommand != "" {
_, err = file.WriteString(fmt.Sprintf(" RemoteCommand %s\n", host.RemoteCommand))
if err != nil {
@@ -1044,6 +1056,9 @@ func UpdateSSHHostInFile(oldName string, newHost SSHHost, configPath string) err
if newHost.ProxyJump != "" {
newLines = append(newLines, " ProxyJump "+newHost.ProxyJump)
}
if newHost.ProxyCommand != "" {
newLines = append(newLines, " ProxyCommand="+newHost.ProxyCommand)
}
if newHost.RemoteCommand != "" {
newLines = append(newLines, " RemoteCommand "+newHost.RemoteCommand)
}
@@ -1098,6 +1113,9 @@ func UpdateSSHHostInFile(oldName string, newHost SSHHost, configPath string) err
if newHost.ProxyJump != "" {
newLines = append(newLines, " ProxyJump "+newHost.ProxyJump)
}
if newHost.ProxyCommand != "" {
newLines = append(newLines, " ProxyCommand="+newHost.ProxyCommand)
}
if newHost.RemoteCommand != "" {
newLines = append(newLines, " RemoteCommand "+newHost.RemoteCommand)
}
@@ -1188,6 +1206,9 @@ func UpdateSSHHostInFile(oldName string, newHost SSHHost, configPath string) err
if newHost.ProxyJump != "" {
newLines = append(newLines, " ProxyJump "+newHost.ProxyJump)
}
if newHost.ProxyCommand != "" {
newLines = append(newLines, " ProxyCommand="+newHost.ProxyCommand)
}
if newHost.RemoteCommand != "" {
newLines = append(newLines, " RemoteCommand "+newHost.RemoteCommand)
}
@@ -1242,6 +1263,9 @@ func UpdateSSHHostInFile(oldName string, newHost SSHHost, configPath string) err
if newHost.ProxyJump != "" {
newLines = append(newLines, " ProxyJump "+newHost.ProxyJump)
}
if newHost.ProxyCommand != "" {
newLines = append(newLines, " ProxyCommand="+newHost.ProxyCommand)
}
if newHost.RemoteCommand != "" {
newLines = append(newLines, " RemoteCommand "+newHost.RemoteCommand)
}
@@ -1742,6 +1766,9 @@ func UpdateMultiHostBlock(originalHosts, newHosts []string, commonProperties SSH
if commonProperties.ProxyJump != "" {
newLines = append(newLines, " ProxyJump "+commonProperties.ProxyJump)
}
if commonProperties.ProxyCommand != "" {
newLines = append(newLines, " ProxyCommand="+commonProperties.ProxyCommand)
}
if commonProperties.RemoteCommand != "" {
newLines = append(newLines, " RemoteCommand "+commonProperties.RemoteCommand)
}
@@ -1828,6 +1855,9 @@ func UpdateMultiHostBlock(originalHosts, newHosts []string, commonProperties SSH
if commonProperties.ProxyJump != "" {
newLines = append(newLines, " ProxyJump "+commonProperties.ProxyJump)
}
if commonProperties.ProxyCommand != "" {
newLines = append(newLines, " ProxyCommand="+commonProperties.ProxyCommand)
}
if commonProperties.RemoteCommand != "" {
newLines = append(newLines, " RemoteCommand "+commonProperties.RemoteCommand)
}