Repository navigation
fix(current-working-dir): don't count ~ as a segment, and preview every segment count - #685
Open
eric-engberg wants to merge 1 commit into
Open
eric-engberg wants to merge 1 commit into
eric-engberg wants to merge 1 commit into
Conversation
…ry segment count
With abbreviate-home on, the leading "~" counted as one of the kept
segments. ~/a/b with segments=2 had three parts, so it rendered
"~/.../a/b" though nothing was left out; /a/b with segments=2 renders
"/a/b". The "~" is always kept in front, so it no longer counts.
The preview was a set of fixed strings for one or two segments, so
segments=3 or 4 still previewed two (".../example/project"), and those
strings didn't come from the sample path itself. The preview now runs
the same segment logic over the sample path that a real path goes
through, so it shows what the setting produces.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
~as one of the kept segments. With abbreviate-home on and segments set to 2,~/Projects/my-projectnow renders as~/Projects/my-projectinstead of~/.../Projects/my-project, which elided nothing..../Documents/Projects/my-projectinstead of.../example/project.Why
~counted as a segment: the widget splits the path and elides it when there are more parts than segments. After home abbreviation,~is one of those parts:~/a/b~/.../a/b~/a/b~/a~/.../a~/a~/a/b/c~/.../b/c~/.../b/c/a/b/a/b/a/bThe
~is always kept in front of the..., so counting it meant one segment fewer was ever shown in full, and the...stood for nothing.Preview: the preview was a set of fixed strings for one segment and "more than one". Every count from 2 up previewed
.../example/project(or~/.../Projects/my-projectwith home on), while the status line shows that many segments. The strings also weren't cut from the sample path the preview otherwise shows (/Users/example/Documents/Projects/my-project): one segment previewed.../project.How
The segment logic moves into a
keepLastSegmentshelper that both the status line and the preview call. It skips a leading~part when counting and keeps it in front as before. Everything else works as before: separator detection (/or\), UNC and leading separators, and paths outside home. Fish style ignores segments, as before. The preview runs the helper over its sample path (/Users/example/Documents/Projects/my-project, or~/Documents/Projects/my-projectwith home on), so it shows exactly what the setting does to that path. Previews for one and two segments change too, to segments of the sample path:.../my-projectand.../Projects/my-project.Demo
The TUI preview is its built-in sample path. The status line is piped with sample payloads under a scratch home.
Setting segments to 3 in the TUI:
Powerline: before
Powerline: after
Plain: before
Plain: after
Home abbreviation with segments set to 2, for a directory two levels below home and one three levels below (unchanged):
Powerline: before
Powerline: after
Plain: before
Plain: after
Testing
mainfirst:~isn't counted (2 of~/Projects/my-project, 1 of~/Projects); the preview at 1 to 5 segments, and at 3 and 4 with home on.bun test: 2791 pass, 0 fail.bun run lintpasses.main(24 of 24 there, 33 of 33 here). ItsbeforeEachspies onos.homedir, which Node doesn't allow. So I checked the built CLI instead: under Bun 1.4.2 and Node 26.10.0 with a scratchHOME,~/Projects/my-project(2) and~/Projects(1) render without....~/Documents/Projects/my-project(2),/a/band/a/b/crender as onmain. Both runtimes agree.main(the payload's cwd isn't under home). The TUI opens and exits cleanly under both.