Skip to content

Fix column placeholders dropping the first selection row#11

Merged
myme merged 1 commit into
mainfrom
fix-columns-drop-first-row
Jun 29, 2026
Merged

Fix column placeholders dropping the first selection row#11
myme merged 1 commit into
mainfrom
fix-columns-drop-first-row

Conversation

@myme

@myme myme commented Jun 29, 2026

Copy link
Copy Markdown
Owner

Problem

Running a command whose argument is a column-format placeholder, e.g.

### `git-worktree ${git-worktrees | cols 1}`

drops the first row from the selection list. With three worktrees you only get two options, and the displayed titles are shifted by one relative to the values they select — so picking a row hands back the wrong path.

Cause

In resolveCmd (src/Nixon/Command/Run.hs) the title list was built with an unconditional drop 1 (intended to strip a header line), while the value list (parseColumns hasHeader) only dropped a row when hasHeader was set:

(title, value) <- (drop 1 &&& parseColumns') . map lineToText <$> shell_to_list linesEval
select $ zipWith Select.WithTitle title value

For a plain cols (no +h, hasHeader = False) the values kept every row but the titles were one shorter, so zipWith truncated to the shorter list — losing the first row and misaligning the rest. With cols+h the two happened to stay consistent, which is why only the headerless case was affected.

Fix

Extract the title/value pairing into a pure, testable formatColumns helper in Nixon.Format that only drops the header row when hasHeader is set, keeping titles and values aligned in both cases.

Tests

Added regression tests in Test.Nixon.Format.Columns covering both the headerless case (the reported bug) and the +h case. Verified the headerless test fails against the old behavior before the fix and passes after. Full suite: 126 examples, 0 failures.

Column-format placeholders (`${cmd | cols N}`) always dropped the first
output row and shifted the remaining titles relative to their values.

In `resolveCmd` the title list was built with an unconditional `drop 1`
(to strip a header line), while the value list dropped a row only when
`hasHeader` was set. For a plain `cols` (no `+h`) the value list kept
every row but the title list was one shorter, so `zipWith` truncated to
the shorter list and the first row was lost. The surviving rows also had
their titles shifted by one relative to their values.

Extract the title/value pairing into a pure `formatColumns` helper that
only drops the header when `hasHeader` is set, and cover it with a
regression test.
@myme myme merged commit 3d14823 into main Jun 29, 2026
3 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