Skip to content

feat: path_shorten using extmarks#2520

Merged
ibhagwan merged 1 commit intomainfrom
path_shorten_extmarks
Mar 1, 2026
Merged

feat: path_shorten using extmarks#2520
ibhagwan merged 1 commit intomainfrom
path_shorten_extmarks

Conversation

@ibhagwan
Copy link
Copy Markdown
Owner

I'm quite mind blown, this PR was one shot from a single prompt in opencode using subagents, the prompt:

  ┃  Can you take a look at issue #2517 in fzf-lua github repo and read the linked comment from discussion
  ┃  #2516 and see if you can come up with a PR to enable path_shorten using neovim extmarks?

I haven't reviewed the code yet, but my agents (3 different models) did and this is what they found:
image

Note it chose to use a different option as it affects the main fzf window only within neovim and can't be used in fzf-tmux so to use this you need to use winopts.path_shorten:

:FzfLua files winopts.path_shorten=true
image

Honestly, this is quite shocking, the level of understanding of a very intricate problem and solution from a two-liner prompt...

The review seems to be on-point too (which I'll soon push it's changes too).

@ibhagwan ibhagwan force-pushed the path_shorten_extmarks branch 4 times, most recently from 264608c to 645e973 Compare January 18, 2026 02:14
@nenahp
Copy link
Copy Markdown

nenahp commented Jan 18, 2026

that's interesting. it seems the shorten parts can be highlighted correctly

maybe just not work well with fd --color=always

Tested it work with term ansi hl, I see the code conceal the part not coverted by path_shorten length, so it's a better solution.

@ibhagwan ibhagwan force-pushed the path_shorten_extmarks branch 3 times, most recently from 53dac58 to e4b5075 Compare January 18, 2026 03:07
Comment thread lua/fzf-lua/win.lua Outdated
@ibhagwan
Copy link
Copy Markdown
Owner Author

that's interesting. it seems the shorten parts can be highlighted correctly

maybe just not work well with fd --color=always

Tested it work with term ansi hl, I see the code conceal the part not coverted by path_shorten length, so it's a better solution.

I also tested with ANSI hl and it worked, also worked with path_shorten=2 (3,etc...)

Can also use nvim_set_decoration_provider with ephemeral extmark here. It will apply on redraw, so no need to clear marks manually on redraw. return false in on_win to filter non fzf win.

I'll let the AI fix it's own work let's see what it comes up with :-)

@ibhagwan
Copy link
Copy Markdown
Owner Author

cffe957

image

@barrettruth
Copy link
Copy Markdown
Contributor

insane!!! so cool (and scary) to see. cool feature nonetheless

@ibhagwan
Copy link
Copy Markdown
Owner Author

insane!!! so cool (and scary) to see. cool feature nonetheless

It’s a new era, we’re soon gonna be redundant, this was done with Opus 4.5, since then we had Opus 4.6, Codex 5.3, Kimi 2.5, MiniMax 2.5, Qwen 3.5 and more I can’t recall ATM, all can handle complex tasks even better than this, didn’t think I’d say this one day but soon (if not already) they’ll be coding better than me :)

@ibhagwan
Copy link
Copy Markdown
Owner Author

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a winopts.path_shorten feature to visually shorten paths in the fzf window using extmarks, which is a great enhancement. The implementation is well-contained within a new PathShortener class and is correctly integrated into the FzfWin lifecycle. The logic for identifying and shortening path components is thorough, handling various line formats and edge cases like Windows paths. I have one suggestion to improve code quality by refactoring duplicated logic for UTF-8 character counting. Overall, this is a solid contribution.

Comment thread lua/fzf-lua/win.lua Outdated
@barrettruth
Copy link
Copy Markdown
Contributor

lmao 💀 the immediate follow-up with gemini review

@ibhagwan
Copy link
Copy Markdown
Owner Author

lmao 💀 the immediate follow-up with gemini review

What’s better than a model reviewing a model lol

@barrettruth
Copy link
Copy Markdown
Contributor

hm... maybe you reviewing my pr 🤔

@ibhagwan
Copy link
Copy Markdown
Owner Author

hm... maybe you reviewing my pr 🤔

Just write /gemini review in your PR as a new message let’s see what it says

@gemini-code-assist
Copy link
Copy Markdown

Acknowledged. I am now performing a code review for this pull request.

@ibhagwan ibhagwan force-pushed the path_shorten_extmarks branch 3 times, most recently from 7be8ff2 to 67901ac Compare March 1, 2026 17:49
@ibhagwan
Copy link
Copy Markdown
Owner Author

ibhagwan commented Mar 1, 2026

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new feature for path shortening using Neovim's extmarks, implemented within a PathShortener class and integrated with the fzf window's lifecycle. However, a potential Denial of Service vulnerability was identified in the PathShortener._apply_line function in lua/fzf-lua/win.lua, where maliciously crafted long lines could cause the Neovim UI to hang. Additionally, there's an issue with the use of certain Neovim API functions for string manipulation that appears incorrect and could cause issues, for which a specific code suggestion has been provided.

Comment thread lua/fzf-lua/win.lua
Comment thread lua/fzf-lua/win.lua
@ibhagwan ibhagwan force-pushed the path_shorten_extmarks branch from 67901ac to 3d019a2 Compare March 1, 2026 18:13
Use `winopts.path_shorten` (instead of `path_shorten`)

Fix #2517
@ibhagwan ibhagwan force-pushed the path_shorten_extmarks branch from 3d019a2 to 2643d21 Compare March 1, 2026 18:14
@ibhagwan ibhagwan merged commit cea4145 into main Mar 1, 2026
3 checks passed
@ibhagwan ibhagwan deleted the path_shorten_extmarks branch March 1, 2026 18:17
@liskin
Copy link
Copy Markdown
Contributor

liskin commented Mar 9, 2026

Looks a bit funny with the fzf-native profile:

2026-03-09-140957_1127x754_scrot

@ibhagwan
Copy link
Copy Markdown
Owner Author

ibhagwan commented Mar 9, 2026

Looks a bit funny with the fzf-native profile:

2026-03-09-140957_1127x754_scrot

Ty for reporting #2607

@liskin
Copy link
Copy Markdown
Contributor

liskin commented Mar 9, 2026

(sorry for not opening a separate issue btw, I just didn't have enough time/spoons to fill in the form and try to come up with a reproducer using mini.sh; seemed that if I just post a screenshot it'll be obvious what's going on and it seemed unlikely this is my config messing stuff up)

@ibhagwan
Copy link
Copy Markdown
Owner Author

ibhagwan commented Mar 9, 2026

(sorry for not opening a separate issue btw, I just didn't have enough time/spoons to fill in the form and try to come up with a reproducer using mini.sh; seemed that if I just post a screenshot it'll be obvious what's going on and it seemed unlikely this is my config messing stuff up)

All good this is very obviously a bug and easily reproducible as the terminal text shifts due to the extmarks, may or may not be fixable, I’ll explore :)

@liskin
Copy link
Copy Markdown
Contributor

liskin commented Mar 9, 2026

may or may not be fixable, I’ll explore :)

If it helps prioritise, I don't think I'll actually be using this myself. 🙂
I just saw it in the changelog, gave it a try, saw that it a) glitches with right-split native previewer, b) shortens all paths unconditionally regardless of them being short/long, and decided to disable it again - mainly because of b).

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.

4 participants