mirror of
https://github.com/Gu1llaum-3/sshm.git
synced 2026-01-27 03:04:21 +01:00
fix: SSH identity file paths with spaces and edit form navigation
- Quote IdentityFile paths containing spaces to prevent SSH config errors - Fix edit form ESC/Ctrl+C to return to main view instead of quitting - Improve edit form navigation consistency with add form - Fix focus management when adding host fields with Ctrl+A
This commit is contained in:
@@ -418,6 +418,20 @@ func getMainConfigPath() string {
|
||||
return absPath
|
||||
}
|
||||
|
||||
// formatSSHConfigValue formats a value for SSH config file, adding quotes if necessary
|
||||
func formatSSHConfigValue(value string) string {
|
||||
if value == "" {
|
||||
return value
|
||||
}
|
||||
|
||||
// If the value contains spaces, wrap it in quotes
|
||||
if strings.Contains(value, " ") {
|
||||
return `"` + value + `"`
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
|
||||
// AddSSHHost adds a new SSH host to the config file
|
||||
func AddSSHHost(host SSHHost) error {
|
||||
configPath, err := GetDefaultSSHConfigPath()
|
||||
@@ -495,7 +509,7 @@ func AddSSHHostToFile(host SSHHost, configPath string) error {
|
||||
}
|
||||
|
||||
if host.Identity != "" {
|
||||
_, err = file.WriteString(fmt.Sprintf(" IdentityFile %s\n", host.Identity))
|
||||
_, err = file.WriteString(fmt.Sprintf(" IdentityFile %s\n", formatSSHConfigValue(host.Identity)))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -795,7 +809,7 @@ func UpdateSSHHostInFile(oldName string, newHost SSHHost, configPath string) err
|
||||
newLines = append(newLines, " Port "+newHost.Port)
|
||||
}
|
||||
if newHost.Identity != "" {
|
||||
newLines = append(newLines, " IdentityFile "+newHost.Identity)
|
||||
newLines = append(newLines, " IdentityFile "+formatSSHConfigValue(newHost.Identity))
|
||||
}
|
||||
if newHost.ProxyJump != "" {
|
||||
newLines = append(newLines, " ProxyJump "+newHost.ProxyJump)
|
||||
@@ -843,7 +857,7 @@ func UpdateSSHHostInFile(oldName string, newHost SSHHost, configPath string) err
|
||||
newLines = append(newLines, " Port "+newHost.Port)
|
||||
}
|
||||
if newHost.Identity != "" {
|
||||
newLines = append(newLines, " IdentityFile "+newHost.Identity)
|
||||
newLines = append(newLines, " IdentityFile "+formatSSHConfigValue(newHost.Identity))
|
||||
}
|
||||
if newHost.ProxyJump != "" {
|
||||
newLines = append(newLines, " ProxyJump "+newHost.ProxyJump)
|
||||
@@ -927,7 +941,7 @@ func UpdateSSHHostInFile(oldName string, newHost SSHHost, configPath string) err
|
||||
newLines = append(newLines, " Port "+newHost.Port)
|
||||
}
|
||||
if newHost.Identity != "" {
|
||||
newLines = append(newLines, " IdentityFile "+newHost.Identity)
|
||||
newLines = append(newLines, " IdentityFile "+formatSSHConfigValue(newHost.Identity))
|
||||
}
|
||||
if newHost.ProxyJump != "" {
|
||||
newLines = append(newLines, " ProxyJump "+newHost.ProxyJump)
|
||||
@@ -975,7 +989,7 @@ func UpdateSSHHostInFile(oldName string, newHost SSHHost, configPath string) err
|
||||
newLines = append(newLines, " Port "+newHost.Port)
|
||||
}
|
||||
if newHost.Identity != "" {
|
||||
newLines = append(newLines, " IdentityFile "+newHost.Identity)
|
||||
newLines = append(newLines, " IdentityFile "+formatSSHConfigValue(newHost.Identity))
|
||||
}
|
||||
if newHost.ProxyJump != "" {
|
||||
newLines = append(newLines, " ProxyJump "+newHost.ProxyJump)
|
||||
@@ -1469,7 +1483,7 @@ func UpdateMultiHostBlock(originalHosts, newHosts []string, commonProperties SSH
|
||||
newLines = append(newLines, " Port "+commonProperties.Port)
|
||||
}
|
||||
if commonProperties.Identity != "" {
|
||||
newLines = append(newLines, " IdentityFile "+commonProperties.Identity)
|
||||
newLines = append(newLines, " IdentityFile "+formatSSHConfigValue(commonProperties.Identity))
|
||||
}
|
||||
if commonProperties.ProxyJump != "" {
|
||||
newLines = append(newLines, " ProxyJump "+commonProperties.ProxyJump)
|
||||
@@ -1549,7 +1563,7 @@ func UpdateMultiHostBlock(originalHosts, newHosts []string, commonProperties SSH
|
||||
newLines = append(newLines, " Port "+commonProperties.Port)
|
||||
}
|
||||
if commonProperties.Identity != "" {
|
||||
newLines = append(newLines, " IdentityFile "+commonProperties.Identity)
|
||||
newLines = append(newLines, " IdentityFile "+formatSSHConfigValue(commonProperties.Identity))
|
||||
}
|
||||
if commonProperties.ProxyJump != "" {
|
||||
newLines = append(newLines, " ProxyJump "+commonProperties.ProxyJump)
|
||||
|
||||
Reference in New Issue
Block a user