Skip to content

Commit c7a8051

Browse files
unhappychoiceclaude
andcommitted
fix(install/rc): trim trailing newline when embedding source_line
format_block expects source_line to be a single line; Nushell's source_line is the whole snippet from include_str! which always ends in '\n', so the previous format string left a blank line between the last snippet line and the close marker. trim_end_matches('\n') is a no-op for the existing one-liner shells and makes the Nushell block visually consistent with them. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent 280fa76 commit c7a8051

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

‎src/install/rc.rs‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,14 @@ fn find_block(contents: &str) -> Option<(usize, usize)> {
154154
}
155155

156156
fn format_block(shell: Shell) -> String {
157+
// `trim_end_matches('\n')` keeps spacing consistent for shells whose source_line is
158+
// a single inline command (no trailing newline) and the Nushell case where it's the
159+
// full snippet from `include_str!` (always terminated with `\n`) — without trimming
160+
// the latter would leave a blank line before the close marker.
157161
format!(
158162
"{open}\n# Added by `splashboard install`. Safe to remove.\n{line}\n{close}\n",
159163
open = MARKER_OPEN,
160-
line = shell::source_line(shell),
164+
line = shell::source_line(shell).trim_end_matches('\n'),
161165
close = MARKER_CLOSE,
162166
)
163167
}
@@ -264,6 +268,9 @@ trailing\n"
264268
assert!(contents.contains("env_change.PWD"));
265269
assert!(contents.contains("^splashboard"));
266270
assert_eq!(contents.matches(MARKER_OPEN).count(), 1);
271+
// No blank line between the last snippet line and the close marker — the snippet
272+
// is sourced from a file that always ends in `\n`, so format_block must trim it.
273+
assert!(contents.contains(&format!("^splashboard\n{MARKER_CLOSE}")));
267274

268275
let up_to_date = wire_shell_rc(Shell::Nushell, Some(rc.clone())).unwrap();
269276
assert_eq!(up_to_date.action, RcAction::UpToDate);

0 commit comments

Comments
 (0)