GithubHelp home page GithubHelp logo

Comments (9)

zhengpd avatar zhengpd commented on June 26, 2024 4

Here is how I use tui-nvim now, replacing the fm-nvim. It's amazing that I can easily open any command now, not just file managers. Really cool!

" 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

from fm-nvim.

is0n avatar is0n commented on June 26, 2024 1

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
	}
}

from fm-nvim.

is0n avatar is0n commented on June 26, 2024 1

The on_open tip from @is0n doesn't work for me. Don't know what's wrong yet. But I figured out a way to open Ranger & Xplr with current file selected. Try if you think it helps.

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.

from fm-nvim.

zhengpd avatar zhengpd commented on June 26, 2024 1

@is0n tui-nvim is cool and more configurable 👍 Looking forward to the user-defined keybinds.

from fm-nvim.

zacgodinez avatar zacgodinez commented on June 26, 2024 1

Great package 😍
For those interested, I have solved this for my needs, by creating two keybinds for xplr.

["<leader>n"] = { "<cmd>Xplr<cr>", desc = "XPLR cwd" },
["<leader>m"] = { "<cmd>Xplr %:p:h<cr>", desc = "XPLR selected file" },

from fm-nvim.

gkzhb avatar gkzhb commented on June 26, 2024

For lf, we can use require('fm-nvim').Lf(vim.fn.expand('%:p')) to achieve this.

As for ranger, maybe we can provide another function parameter for require('fm-nvim').Ranger() to pass in the selected file so that we can use this lua API to open ranger with current file selected?

from fm-nvim.

zhengpd avatar zhengpd commented on June 26, 2024

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 on_open callback.

from fm-nvim.

zhengpd avatar zhengpd commented on June 26, 2024

The on_open tip from @is0n doesn't work for me. Don't know what's wrong yet. But I figured out a way to open Ranger & Xplr with current file selected. Try if you think it helps.

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 M.Ranger to do it.

from fm-nvim.

avucic avatar avucic commented on June 26, 2024

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 vifm --select= it will fail. Maybe <fm>_cmd option in configuration can accept fn.

from fm-nvim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.