Skip to content

fix: preserve trailing blank lines when adding SSH config fields#66

Merged
Adembc merged 1 commit intomainfrom
fix/formating
Sep 30, 2025
Merged

fix: preserve trailing blank lines when adding SSH config fields#66
Adembc merged 1 commit intomainfrom
fix/formating

Conversation

@Adembc
Copy link
Owner

@Adembc Adembc commented Sep 30, 2025

This PR fixes an edge case where newly added fields could end up outside of their intended Host block when the block was followed by blank lines or comments.

Problem

Previously, if two host entries were separated by a blank line, adding a new key-value entry to the first host would place it after the blank line, shifting the formatting and making it appear detached from the correct host.

Example:

Host example-host
    HostName example-ip
    User root

    Port 302         # <-- incorrectly inserted here
Host example-host-2
    HostName example-ip-2
    Port 22
    User root

Fix

The insertion logic now ensures that:

  • New keys are always inserted inside the host block, directly after the last existing key-value node.

  • Any trailing blank lines or comments remain outside the host block, preserving the original formatting between host definitions.

  • Hosts with no existing key-value pairs will still correctly receive the new field at the top of their block.

Correct behavior after this fix:

Host example-host
    HostName example-ip
    User root
    Port 302

Host example-host-2
    HostName example-ip-2
    Port 22
    User root

@Adembc Adembc merged commit 6ad0719 into main Sep 30, 2025
2 checks passed
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.

1 participant