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
Open browser with current file selected #13
Comments
I've gotten this to work, although, it is very hacky. 😅 require('fm-nvim').setup{
cmds = {
ranger_cmd = "ranger --selectfile=" .. vim.fn.expand("%:p")
},
on_open = {
function()
require('fm-nvim').setup{
cmds = {
ranger_cmd = "ranger --selectfile=" .. vim.fn.expand("%:p")
},
}
end
}
} |
For As for |
It would be best to implement it as an option, like: require('fm-nvim').setup {
focus_selected_file = true
} So that new users wouldn't have to know how to set up the |
The The lua part: -- vim/lua/fm_open.lua
-- workaround for selected file issue: https://github.com/is0n/fm-nvim/issues/13
-- command! -nargs=? -complete=dir Ranger :lua require'fm_open'.open('Ranger', '<f-args>')
local M = {}
local fm_nvim = require('fm-nvim')
M.open = function(fn, dir)
if not fm_nvim[fn] then
print('Invalid file manager.')
return false
end
local fpath = vim.fn.expand('%:p')
local override_cmds = {
ranger_cmd = 'ranger',
xplr_cmd = 'xplr'
}
if dir == nil or dir == '' then
-- If no dir arg passed, open fm with current file selected
override_cmds = {
ranger_cmd = 'ranger --selectfile ' .. fpath,
xplr_cmd = 'xplr ' .. fpath
}
fm_nvim.setup { cmds = override_cmds }
-- fn-nvim append '.' to ranger_cmd, which causes Ranger opens 2 paths
-- so we pass the empty '' as dir arg to avoid this behavior
dir = override_cmds[string.lower(fn) .. '_cmd'] and '' or '.'
else
-- If dir passed, undo the fpath cmds
fm_nvim.setup { cmds = override_cmds }
end
fm_nvim[fn](dir)
end
return M The vim commands part: " vim/after/plugin/fm-nvim.vim
command! -nargs=? -complete=dir Ranger :lua require'fm_open'.open('Ranger', '<f-args>')
command! -nargs=? -complete=dir Xplr :lua require'fm_open'.open('Xplr', '<f-args>') Still, I wish fm-nvim got a builtin option for selected file in future, maybe by rewriting the builtin functions like |
This work is amazing! Support for Xplr was definitely a nice touch 👍🏽 In case you might want a cleaner approach to this, consider checking out tui-nvim. The README includes code that opens ranger with the current file selected in just a few lines. |
@is0n tui-nvim is cool and more configurable 👍 Looking forward to the user-defined keybinds. |
Here is how I use " vim/plugin/tui-nvim-cmds.vim
command! Btop :lua require('tui-nvim-cmds').btop()<CR>
command! -nargs=? -complete=file Ranger :lua require('tui-nvim-cmds').ranger(<f-args>)<CR>
command! -nargs=? -complete=file Xplr :lua require('tui-nvim-cmds').xplr(<f-args>)<CR> -- vim/lua/tui-nvim-cmds.lua
local M = {}
M.btop = function()
local temp = '/tmp/tui-nvim-btop'
require('tui-nvim'):new {
cmd = 'btop',
temp = temp,
width = 1,
height = 1,
}
end
M.ranger = function(path)
local temp = '/tmp/tui-nvim-ranger'
if path == nil or path == '' then
path = vim.fn.expand('%:p')
end
require('tui-nvim'):new {
cmd = 'ranger --choosefiles=' .. temp .. ' --selectfile=' .. vim.fn.fnameescape(path),
temp = temp,
width = 1,
height = 1,
}
end
M.xplr = function(path)
local temp = '/tmp/tui-nvim-xplr'
if path == nil or path == '' then
path = vim.fn.expand('%:p')
end
require('tui-nvim'):new {
cmd = 'xplr ' .. vim.fn.fnameescape(path),
temp = temp,
width = 1,
height = 1,
}
end
return M |
Great package 😍
|
For vifm currently I have this ugly way to open and select file maps.n["<leader>fe"] = {
function()
local dir_arg = vim.fn.expand("%:p:h")
local current_file = vim.fn.expand("%:p")
if current_file ~= "" then
dir_arg = "--select=" .. current_file
end
require("fm-nvim").Vifm(dir_arg)
end,
}
when you run vifm with only |
This is an awesome plugin! I used to have a really big function I wrote that would open ranger, and you have implemented it even better.
I'm not sure how relevant this would be to other file managers, but one thing I had before (as can be seen in the link above, my
selectFile
argument) is opening ranger to the folder of the current file, with the current file selected.Is this something possible to do with your plugin? I'm not necessarily requesting a feature as this may only prove to be possible or easy with a subset of your supported browsers (I know it is on vifm as well, as I used to use that one and do the same thing). But I would like some help making this work. Perhaps I can write something to do this in an
on_open
function?I was playing around with the lua API and I will definitely be able to at least open the file browser in the current directory, and that will certainly be good enough as a fallback until/unless we can figure out how to also select the current file.
Thank you for your time.
The text was updated successfully, but these errors were encountered: