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

feat: terminal cmd preview for directories #74

Closed
wants to merge 2 commits into from

Conversation

fdschmidt93
Copy link
Member

Ah, this is a tricky one. This allows overwriting the directory previewer with a function like so

function(path)
  return "ls -la --color=always " .. path .. " | less -r"
end

would show ls -la output like in the terminal

The video shows tree as a previewer. Colors may or may not work depending on compatability with a pager.

fb_trees.mp4

I hope someone appreciates this hack 😆

@ikerurda
Copy link
Contributor

Cool!
But when quitting the picker in insert mode, it stays in insert mode... not sure why

@fdschmidt93
Copy link
Member Author

Thanks for test driving!

I can reproduce that, but not really sure as to why that would happen 😅

In general, it seems to be associated with terminal previewers, e.g.

:lua require "telescope.builtin".find_files { previewer = require "telescope.previewers.term_previewer".cat.new({})} also has that issue.

Probably related to the prompt buffer bugs.

@fdschmidt93
Copy link
Member Author

fdschmidt93 commented Jan 19, 2022

The fix is quite hacky, but seems to work as intended so long as anyone would want to return to insert mode coming off of the file_browser. I'd probably let anyone who ever (if ever anyone) runs into the issue to fix that.

Could you please confirm it also saves the issue on your end? :)

@ikerurda
Copy link
Contributor

Yes, this fixes it :)

@kkharji
Copy link
Member

kkharji commented Jan 26, 2022

😍This just what I was looking for. does it need more tests?

@fdschmidt93
Copy link
Member Author

No, primarily documentation so people will understand what they can pass as dir_preview then.

I'll try to do that tonight.

@Conni2461
Copy link
Member

Conni2461 commented Jan 26, 2022

We should drop scandir.ls and everything with it. It was a mistake. Makes highlighting for unix like and windows systems the same but offers 0 flexibility. Windows just only gives us dirs

But new_termopen_previewer is still leaking buffers. Just do :ls!
A solution would be new_buffer_previewer with vim.api.nvim_open_term as a new term_previewer. Would also remove the less -r part.

I would suggest to not do this here but rather in core

@kkharji
Copy link
Member

kkharji commented Jan 26, 2022

We should drop scandir.ls and everything with it. It was a mistake. Makes highlighting for unix like and windows systems the same but offers 0 flexibility. Windows just only gives us dirs

But new_termopen_previewer is still leaking buffers. Just do :ls! A solution would be new_buffer_previewer with vim.api.nvim_open_term as a new term_previewer. Would also remove the less -r part.

I would suggest to not do this here but rather in core

No way it should be dropped @Conni2461 it extremely fast and we have end up creating it for a reason. Yah I agree on the flexibility part but that just a render function need to be exposed and a set of themes to be built upon it. It's extremely easy t build tree structure or hide certain information.

I can take a look on increasing it flexibility if you like.

@fdschmidt93
Copy link
Member Author

One thing I've planned on doing eventually for telescope-file-browser.nvim is expose the underlying methods of plenary.scandir.ls such that the make_entry of the file_browser can make use of those.

The idea is that make_entry into some kind of builder pattern such that users can customize it more to their liking and possible toggle, for instance.

  1. Open file browser
  2. Toggle file size
  3. Be able to sort by file size
  4. Toggle off file size

What I nevertheless really like would be incorporating nvim_open_term into the buffer previewer. We could provide a hook (they are in need of a clean up anyways I suppose, should probably be hook = { filetype = function(...) end, filesize = function(...) end rather than individual functions), for conditional terminal preview. I think that way, we can maybe fully deprecate term-previewers from telescope and just have one properly clean main previewer interface. Unifies scrolling, cleanup, etc. But maybe I'm missing something.

@fdschmidt93
Copy link
Member Author

I'll be working on this upstream most likely in a more universal solution. Let's close this.

@yingzhu146
Copy link

@fdschmidt93 this looks amazing! I think this (tree as command) is also my interpretation of what #165 was hinting at which I'd love since that's the default behavior of https://github.com/Canop/broot which I currently still use for exploration.

Do you think this could be useful for non-directories too?

https://github.com/jarun/nnn allows specifying it per file-type via plugin https://github.com/jarun/nnn/blob/master/plugins/preview-tui

I think that would be extremely powerful. Just some ideas for use cases

directory preview:

tree via exa --tree --icons

file preview:

head -l50 | hexyl: binaries
vd for csv (https://www.visidata.org/)
fx for json
euporie --dump for jupyter notebooks (https://github.com/joouha/euporie)

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.

5 participants