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

Ability to explore directories within kakoune #4014

Open
cole-h opened this issue Jan 8, 2021 · 8 comments
Open

Ability to explore directories within kakoune #4014

cole-h opened this issue Jan 8, 2021 · 8 comments

Comments

@cole-h
Copy link
Contributor

cole-h commented Jan 8, 2021

Feature and Usecase

I would like to be able to explore directories from within kakoune, so that when I run kak on a directory and not a file (usually accidentally), I can somehow navigate to one of the contained files, akin to vim's netrw feature.

I'd also settle for being able to hook into the error that happens when running kak on a directory, so that I can lift from https://github.com/TeddyDD/kakoune-edit-or-dir to satisfy this. I found #1056, but it was closed without a(n obvious) solution. I don't consider connect.kak a solution to this unless kak grows libvterm integration (because connect.kak doesn't work over SSH unless I use tmux, which I don't (want to) use all the time).

@Screwtapello
Copy link
Contributor

Inside Kakoune, if you type :e path/to/some/dir/ you should get a completion menu of the contents of that path, which is not quite as nice as a fully-interactive filesystem browser, but is nicer than a plain error message. LIkewise from the shell, after typing kak path/to/some/dir/ you get the opportunity to play with tab-completion — it's not quite as nice as Kakoune's completion, but it's better than nothing.

Perhaps a better solution would be something like a BufCreatePre hook, with the special rule that if :edit is invoked inside the hook, the original :edit command is cancelled and Kakoune does not attempt to open the original path for reading. Then you could do things like:

hook global BufCreatePre (.*\.zip)!(.*) %{
    eval %sh{
        workdir=$(mktemp -d)
        cd "$workdir"
        unzip "$kak_hook_param_capture_1" "$kak_hook_param_capture_2"
        echo edit "$workdir"/"$kak_hook_param_capture_2"
        echo hook buffer BufWritePost %{ nop %sh{ cd "$workdir"; zip "$kak_hook_param_capture_1" "$kak_hook_param_capture_2" } }
    }
}

...to teach Kakoune to edit files stored inside .zip archives with a syntax like path/to/archive.zip!inner/path/to/file.txt

@tototest99
Copy link

Hello,
There was a lot of recent posts on the discourse forum, with featureful terminal file managers. Respecting Kakoune design you can plug one in different ways (plugin, connect, sh launcher incorporating the choice depending on the file you pass as argument, etc.).
imho a netrw is out of scope and another burden on the maintainers.

@cauebs
Copy link

cauebs commented Jan 22, 2021

I think it's even more useful with zips and tars than plain directories. It's one of the few things I miss from vim.

@benjaminwil
Copy link

benjaminwil commented Feb 4, 2022

I just came across another real-world use case where it would be convenient for Kakoune to handle being given a directory.

Bundler, the defacto package manager for RubyGems, provides a command bundle open to open up the source code of external dependencies in one's Gemfile. (i.e. bundle open nokogiri.)

It opens the editor assigned to EDITOR and puts you in the root directory of that gem dependency. Vim handled this with netrw, and GUI editors seem to also handle this okay.

Now that my EDITOR is set to Kakoune, I can't use this command. Kakoune opens to a text error, and there doesn't seem to be an easy way to get the working directory—which would be the root of the dependency's source code, I would think.

@krobelus
Copy link
Contributor

krobelus commented Feb 4, 2022 via email

@sidkshatriya
Copy link
Contributor

There is, try :echo %sh{pwd}

It is easy but only for someone with some experience with kakoune. There has been a lot of discussion around pwd. See my (failed) attempt to get this into core #4431

The fact that this is brought up reasonably regularly means that it continues to be a paper cut, whether or not @mawww agrees with it. Anyways, I've made my peace with it and accepted that it is likely never to be incorporated.

@benjaminwil
Copy link

There is, try :echo %sh{pwd}

Of course, thank you. So if I can gracefully handle the error state and either a) do something with $PWD or b) pre-fill :edit <tab> in Kakoune, I could be very happy. But I am not yet clear on whether there's a hook I could use, or how I might rescue from this specific error.

@krobelus
Copy link
Contributor

krobelus commented Feb 4, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants