telescope-file-browser.nvim
telescope-file-browser.nvim copied to clipboard
fix: allow netrw to handle url openings when `hijack_netrw = true`
netrw handles opening of urls via an autcmd when doing nvim <url> or :e <url>.
Disabling netrw entirely when hijack_netrw = true had the unintended side effect of breaking the above mentioned feature so I'm removing the disabling of netrw.
Closes #149
Unfortunately, netrw handles pretty much all of the opening procedure for files, streams, directories, etc. As you found, preventing it from initializing prevents alot of stuff (EG, you cant browse Tars anymore, you cant open URI's with Netrw remote management, etc).
What you might consider instead is using the in built BufReadCmd and FileReadCmd auto commands, checking to see if the handle being opened is a local directory (likely via plenary?) and then handling it however you want there.
I do something ish similar in my plugin to sidestep netrw while still letting Netrw exist and do whatever it needs to do (it also allows me to let it handle things I cant handle)
Yeah I did look into BufReadCmd a bit and saw how integral netrw is to vim.
This PR will let netrw exist, so you will be able to open urls and such, even do :Ex to open the netrw file explorer but rest of the autocmd I set up in #111 should still allow for hijacking netrw only when opening directories.
Sorry for the late feedback.
I'm honestly not at all invested in this feature but
This PR will let netrw exist, so you will be able to open urls and such, even do :Ex to open the netrw file explorer but rest of the autocmd I set up in https://github.com/nvim-telescope/telescope-file-browser.nvim/pull/111 should still allow for hijacking netrw only when opening directories.
this line of reasoning seems intuitive to me and I was about to merge this thinking this is good-to-go. I've briefly tested this PR and it breaks with opening a folder from the shell (nvim . or nvim ./telescope-file-browser/) and opens netrw instead, which I suppose is unintended. Please double check that your PR doesn't break original features.
Are you sure you have hijack_netrw = true? I'm not able to reproduce your behavior - nvim . & nvim /lua both open the telescope file browser for me in the passed directory.
Are you sure you have hijack_netrw = true?
Yes. I have no netrw-related settings apart from hijack_netrw.
Not entirely sure what's going on, but I've created a minimal config with which it works. Unfortunately, it doesn't work with my config for which I really have no clue why that would be. Ideally, we figure out as to why that could be.
Any thoughts?
(first-time start up installs, second time it works)
vim.cmd [[set runtimepath=$VIMRUNTIME]]
vim.cmd [[set packpath=/tmp/nvim/site]]
local package_root = "/tmp/nvim/site/pack"
local install_path = package_root .. "/packer/start/packer.nvim"
local function load_plugins()
require("packer").startup {
{
"wbthomason/packer.nvim",
{ "nvim-lua/plenary.nvim" },
-- { "nvim-telescope/telescope-file-browser.nvim" },
{ "jamestrew/telescope-file-browser.nvim", branch = "hijack-netrw-enable-netrw" },
{
"nvim-telescope/telescope.nvim",
config = function()
require("telescope").setup {
extensions = {
file_browser = {
hijack_netrw = true,
},
},
}
require("telescope").load_extension "file_browser"
end,
},
-- ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
},
config = {
package_root = package_root,
compile_path = install_path .. "/plugin/packer_compiled.lua",
display = { non_interactive = true },
},
}
local status, _ = pcall(require, "telescope")
if not status then
vim.cmd [[ PackerSync ]]
end
end
if vim.fn.isdirectory(install_path) == 0 then
print "Installing Telescope and dependencies."
vim.fn.system { "git", "clone", "--depth=1", "https://github.com/wbthomason/packer.nvim", install_path }
end
load_plugins()
As hints
:Telescope autocommands for my config

vs minimal init lua

So netrw may not always be properly handled or something I suppose as for some reason FileExplorer is not cleared appropriately for me.
E: Ok, thanks to require being shown in nvim --startuptime, the answer is pretty simple. For some reason, maybe because of impatient.nvim, the file-browser augroup is set up before netrw as netrw is loader only after telescope and friends. I'm currently trying to more generally circumvent that. However, I haven't yet come up with a fix.
Hey @fdschmidt93, sorry I had abandoned this PR for a while.
If you get a chance, please try this out again with your config. It's still working on mine (I am also using impatient.nvim). If it still doesn't work, I'm not really sure how to go about this. The intricacies of vim/nvim startup is beyond my knowledge....
sorry I had abandoned this PR for a while.
That's ok, it's open source.
If you get a chance, please try this out again with your config.
Yes, works great :) I think we have it.
this line of reasoning seems intuitive to me and I was about to merge this thinking this is good-to-go. I've briefly tested this PR and it breaks with opening a folder from the shell (nvim . or nvim ./telescope-file-browser/) and opens netrw instead, which I suppose is unintended. Please double check that your PR doesn't break original features.
Same issue
Please open a new issue with minimal config and minimal repro steps. AFAICT, all issue here have been fixed and you are the first user to report new problems.
Then, I'm happy to help. Otherwise, I won't, because I don't go on an even longer scavenger hunt.
E: Apologies, my bad, I've just seen you've reported a new issue.