Skip to content

Conversation

tan9
Copy link
Contributor

@tan9 tan9 commented Sep 7, 2025

Summary

  • Added new feature to quickly add servers by parsing SSH commands from clipboard
  • New keybinding v complements the existing Copy SSH (c) functionality
  • Provides a convenient way to import SSH connections from other sources
  • Enhanced copy/paste with metadata preservation for seamless round-trip

Changes

  • ✨ New SSH command parser that supports comprehensive SSH flags and options
  • 🎯 Intelligent alias generation with deduplication and smart numbering
  • 🔄 Round-trip support: copied commands include metadata (alias/tags)
  • 🎨 Updated UI components to show the new keybinding
  • 🛠️ Refactored server form to properly handle pasted data
  • 📝 Updated README documentation
  • ✅ Added comprehensive unit tests for all new features

Features

Supported SSH Command Formats

  • Basic: ssh user@host
  • No user: ssh host (uses current user)
  • With port: ssh user@host -p 2222
  • With identity: ssh user@host -i ~/.ssh/custom_key
  • Complex: ssh -p 2222 -i ~/.ssh/custom_key -J jump@proxy user@host
  • With options: ssh -o StrictHostKeyChecking=no user@host
  • Multiline: Commands with backslash continuation
  • With metadata: # lazyssh-alias:myserver tags:prod,web

Supported SSH Flags

  • -p Port specification
  • -i Identity file (multiple supported)
  • -l Login name
  • -J ProxyJump
  • -L Local forwarding
  • -R Remote forwarding
  • -D Dynamic forwarding
  • -A/-a Agent forwarding
  • -X/-Y X11 forwarding
  • -C Compression
  • -4/-6 IP version forcing
  • -o SSH options (40+ options supported)
  • And many more standard SSH flags

Smart Alias Generation

  • Intelligent deduplication: serverserver_1server_2 (not server_1_1)
  • Extract base names from numbered aliases
  • Simplify domain names (remove www, extract meaningful parts)
  • Handle IP addresses appropriately
  • Skip common usernames (root, ubuntu, ec2-user, centos, etc.)
  • Append non-standard ports to alias

Smart Defaults

  • Default port: 22 (when not specified)
  • Auto-generates unique alias from hostname
  • Preserves all SSH options and configurations

Test Plan

  • Unit tests for SSH parser with 30+ test cases
  • Unit tests for alias generation and deduplication
  • Unit tests for IP address validation (IPv4/IPv6)
  • Round-trip copy/paste functionality verified
  • Build succeeds without linter warnings
  • UI displays new keybinding in all relevant places (hint bar, status bar, details panel)
  • Paste handles duplicate aliases correctly
  • Comments in SSH commands are properly ignored

Technical Details

  • Parser handles multiline SSH commands with backslash continuation
  • Supports extraction of lazyssh metadata from comments
  • Regular comments are automatically filtered out
  • Server form properly differentiates between Add mode (paste) and Edit mode
  • Shared IP validation logic between components
  • Cyclomatic complexity managed through function decomposition

Closes #14

@tan9
Copy link
Contributor Author

tan9 commented Sep 7, 2025

While this PR doesn't directly implement server duplication, it provides a complementary solution that addresses similar use cases as requested in issue #14 "Feature Request: Duplicate/Clone hosts".

What this PR adds

This PR introduces the "Paste SSH" feature (keybinding v), which allows users to quickly add new server entries by pasting SSH commands from their clipboard. This significantly speeds up the process of adding servers, especially when you have SSH commands from:

  • Documentation or wikis
  • Shell history
  • Scripts or configuration files
  • Team communication channels

How it helps with bulk host management

  1. Quick server addition: Instead of manually filling out forms, users can copy an SSH command and instantly create a server entry
  2. Reduces errors: The parser automatically extracts host, user, port, and key information, minimizing manual input errors
  3. Batch workflow: Users can quickly copy multiple SSH commands from a document and add them one by one with just a few keystrokes

Example workflow

# Copy from your documentation:
ssh user@prod-server-01.example.com -p 2222
# Press 'v' in lazyssh, review/edit, save

ssh user@prod-server-02.example.com -p 2222  
# Press 'v' again for the next server

@tan9 tan9 changed the title feat: Add "Add from SSH" feature for parsing SSH commands from clipboard feat: Add "Paste SSH" feature for parsing SSH commands from clipboard Sep 7, 2025
@tan9 tan9 changed the title feat: Add "Paste SSH" feature for parsing SSH commands from clipboard feat: Add "Paste SSH" feature for parsing SSH commands from clipboard and add as new server Sep 7, 2025
@tan9 tan9 changed the title feat: Add "Paste SSH" feature for parsing SSH commands from clipboard and add as new server feat: Add "Paste SSH" feature for parsing SSH commands from clipboard and add as a new server Sep 7, 2025
@tan9 tan9 force-pushed the feat/add-from-ssh branch 6 times, most recently from 46e59e7 to ad36009 Compare September 11, 2025 14:38
@tan9
Copy link
Contributor Author

tan9 commented Sep 11, 2025

Hi @Adembc, I just rebased this PR against the most recent main. Please take a look and let me know your thoughts.

@tan9 tan9 changed the title feat: Add "Paste SSH" feature for parsing SSH commands from clipboard and add as a new server WIP: feat: Add "Paste SSH" feature for parsing SSH commands from clipboard and add as a new server Sep 12, 2025
@tan9 tan9 changed the title WIP: feat: Add "Paste SSH" feature for parsing SSH commands from clipboard and add as a new server [WIP] feat: Add "Paste SSH" feature for parsing SSH commands from clipboard and add as a new server Sep 12, 2025
@tan9 tan9 changed the title [WIP] feat: Add "Paste SSH" feature for parsing SSH commands from clipboard and add as a new server feat: Add "Paste SSH" feature for parsing SSH commands from clipboard and add as a new server Sep 12, 2025
@tan9 tan9 marked this pull request as draft September 12, 2025 02:06
@tan9
Copy link
Contributor Author

tan9 commented Sep 12, 2025

Marked as draft to wait for #48

@tan9 tan9 force-pushed the feat/add-from-ssh branch from ad36009 to 9839e74 Compare September 19, 2025 15:51
@tan9 tan9 marked this pull request as ready for review September 19, 2025 15:58
@tan9 tan9 force-pushed the feat/add-from-ssh branch from 6304319 to ee756e3 Compare September 20, 2025 00:18
- Parse SSH commands from clipboard into domain.Server struct
- Support standard SSH flags (-p, -i, -l, -A, -X, -Y, -C, -4, -6, etc.)
- Support SSH -o options mapping to ssh_config fields
- Handle multiline commands with backslash continuation
- Extract lazyssh metadata (alias and tags) from comments
- Ignore regular comments (lines starting with #)
- Add comprehensive test coverage for various SSH command patterns
- GenerateUniqueAlias: Handle duplicate aliases with smart numbering
  - Extract base name from aliases with existing suffixes (e.g., "123_1" -> "123")
  - Find highest suffix and increment (e.g., "123_1" -> "123_2", not "123_1_1")
- GenerateSmartAlias: Create intelligent aliases from host/user/port
  - Simplify domain names (remove www, extract meaningful parts)
  - Handle IP addresses appropriately
  - Skip common usernames (root, ubuntu, ec2-user, centos, azureuser, etc.)
  - Append non-standard ports to alias
- Add comprehensive test coverage for edge cases
- Add IsIPAddress public function for shared IP validation
- Add GetFieldValidatorsWithContext for context-aware validation
- Implement duplicate alias validation with support for edit mode
- Share IP validation logic between alias generation and validation
- Add comprehensive test coverage for IPv4 and IPv6 addresses
- Add tests for duplicate alias validation scenarios
- Add 'v' keybinding to paste and parse SSH commands from clipboard
- Parse SSH command using the new SSH parser
- Auto-generate unique alias if duplicate detected
- Open server form in Add mode with parsed data
- Update UI components to show 'v' keybinding:
  - Hint bar: Add 'v' to keybinding hints
  - Status bar: Add 'v' Paste SSH to navigation help
  - Server details: Add 'v' to commands list
- Support for clipboard integration via github.com/atotto/clipboard
- Add getExistingAliases helper to retrieve all current aliases
- Add initialData field to ServerForm struct for pre-filling forms
- Add SetInitialData method to set pre-fill data separately from original
- Update getDefaultValues to differentiate between Edit mode (original) and Add mode (initialData)
- Fix issue where pasted servers were incorrectly treated as updates
- Ensure proper mode handling when creating new servers from paste
- Set default port to 22 when port is 0 or unspecified
- Update BuildSSHCommand to include alias and tags as comment
- Format: # lazyssh-alias:<alias> tags:<tag1,tag2,...>
- Add test coverage for BuildSSHCommand with tags
- Enable round-trip capability (copy → paste preserves metadata)
@tan9 tan9 force-pushed the feat/add-from-ssh branch from ee756e3 to 6b5ddfa Compare September 20, 2025 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Duplicate/Clone hosts
1 participant