Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(picker): dynamic path truncation #1461

Open
1 task done
buztard opened this issue Feb 27, 2025 · 1 comment
Open
1 task done

feature(picker): dynamic path truncation #1461

buztard opened this issue Feb 27, 2025 · 1 comment
Labels
enhancement New feature or request

Comments

@buztard
Copy link

buztard commented Feb 27, 2025

Did you check the docs?

  • I have read all the snacks.nvim docs

Is your feature request related to a problem? Please describe.

Currently it's only allowed to use an integer value for path truncation. It's IMO pretty hard to find a value that works well for small and large picker windows.

Describe the solution you'd like

It would be great to have user defined truncate functions. For example:

          formatters = {
            file = {
              truncate = function(path, picker)
                -- normalize go pkg paths and turn
                -- /home/buz/.gvm/pkgsets/go1.24.0/global/pkg/mod/go.opentelemetry.io/otel/[email protected]/tracer.go
                -- into go.opentelemetry.io/otel/[email protected]/tracer.go
                path = path:match("pkg/mod/(.+@.+)$") or path

                -- use 80% of the available window width
                local width = math.max(vim.api.nvim_win_get_width(picker.list.win.win) * 0.8, 40)
                return Snacks.picker.util.truncpath(path, width, { cwd = picker:cwd() })
              end,
            },
          },

Describe alternatives you've considered

Allowing a percentage value like truncate = 0.8 would be an improvement as well

Additional context

No response

@buztard buztard added the enhancement New feature or request label Feb 27, 2025
@disrupted
Copy link
Contributor

duplicate of #1400

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants