MCPcopy Create free account
hub / github.com/Mister-leo/fssh / cmdEdit

Function cmdEdit

cmd/fssh/shell_commands.go:238–377  ·  view source on GitHub ↗

cmdEdit edits an existing SSH host configuration

(ctx *ShellContext, args string)

Source from the content-addressed store, hash-verified

236
237// cmdEdit edits an existing SSH host configuration
238func cmdEdit(ctx *ShellContext, args string) error {
239 hostName := strings.TrimSpace(args)
240 if hostName == "" {
241 fmt.Println("Usage: edit <host>")
242 return nil
243 }
244
245 // Load existing configuration
246 cfg, err := sshconfig.LoadHostConfig(hostName)
247 if err != nil {
248 return fmt.Errorf("host not found: %w", err)
249 }
250
251 fmt.Printf("\n=== Edit Host: %s ===\n", cfg.Name)
252 fmt.Println("Press Enter to keep current value, or type new value")
253
254 // Edit Hostname
255 currentHostname := cfg.Hostname
256 if currentHostname == "" {
257 currentHostname = "(none)"
258 }
259 line, _ := ctx.liner.Prompt(fmt.Sprintf("Hostname [%s]: ", currentHostname))
260 if line = strings.TrimSpace(line); line != "" {
261 cfg.Hostname = line
262 }
263
264 // Edit User
265 currentUser := cfg.User
266 if currentUser == "" {
267 currentUser = "(none)"
268 }
269 line, _ = ctx.liner.Prompt(fmt.Sprintf("User [%s]: ", currentUser))
270 if line = strings.TrimSpace(line); line != "" {
271 if line == "-" {
272 cfg.User = "" // Clear field
273 } else {
274 cfg.User = line
275 }
276 }
277
278 // Edit Port
279 currentPort := cfg.Port
280 if currentPort == "" {
281 currentPort = "22"
282 }
283 line, _ = ctx.liner.Prompt(fmt.Sprintf("Port [%s]: ", currentPort))
284 if line = strings.TrimSpace(line); line != "" {
285 if line == "22" {
286 cfg.Port = "" // Default port, no need to specify
287 } else {
288 cfg.Port = line
289 }
290 }
291
292 // Edit Identity Configuration
293 line, _ = ctx.liner.Prompt("\nChange identity configuration? [y/N]: ")
294 if strings.ToLower(strings.TrimSpace(line)) == "y" {
295 fmt.Println(" 1) Use fssh agent")

Callers 1

runShellFunction · 0.85

Calls 5

LoadHostConfigFunction · 0.92
BuildProxyCommandFunction · 0.92
WriteHostConfigFunction · 0.92
cleanLinerInputFunction · 0.85
reloadHostsFunction · 0.85

Tested by

no test coverage detected