feat: Add "Paste SSH" feature for parsing SSH commands from clipboard and add as a new server#33
feat: Add "Paste SSH" feature for parsing SSH commands from clipboard and add as a new server#33tan9 wants to merge 6 commits intoAdembc:mainfrom
Conversation
|
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 addsThis PR introduces the "Paste SSH" feature (keybinding
How it helps with bulk host management
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 |
46e59e7 to
ad36009
Compare
|
Hi @Adembc, I just rebased this PR against the most recent |
|
Marked as draft to wait for #48 |
ad36009 to
9839e74
Compare
ee756e3 to
6b5ddfa
Compare
|
@Adembc, this PR is ready for review. Perhaps there’s an issue with the GitHub CI pipeline for conventional commit checking. |
|
Hi @tan9. Thanks a lot for your contribution! |
- 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)
6b5ddfa to
8c7c1ce
Compare
|
@Adembc, I’ve completed the rebase. |
Summary
vcomplements the existing Copy SSH (c) functionalityChanges
Features
Supported SSH Command Formats
ssh user@hostssh host(uses current user)ssh user@host -p 2222ssh user@host -i ~/.ssh/custom_keyssh -p 2222 -i ~/.ssh/custom_key -J jump@proxy user@hostssh -o StrictHostKeyChecking=no user@host# lazyssh-alias:myserver tags:prod,webSupported SSH Flags
-pPort specification-iIdentity file (multiple supported)-lLogin name-JProxyJump-LLocal forwarding-RRemote forwarding-DDynamic forwarding-A/-aAgent forwarding-X/-YX11 forwarding-CCompression-4/-6IP version forcing-oSSH options (40+ options supported)Smart Alias Generation
server→server_1→server_2(notserver_1_1)Smart Defaults
22(when not specified)Test Plan
Technical Details
Closes #14