Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
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

enter key doesn't work as expected when using xplr #18

Open
ayushnix opened this issue Feb 9, 2022 · 6 comments
Open

enter key doesn't work as expected when using xplr #18

ayushnix opened this issue Feb 9, 2022 · 6 comments

Comments

@ayushnix
Copy link

ayushnix commented Feb 9, 2022

If I run xplr on my terminal with xplr --print-pwd-with-results and press enter on a directory, xplr exits and prints the parent dir and exits. This is also mentioned on the xplr docs.

However, when using xplr with fm-nvim, when I press the enter key on a dir, the dir gets opened in a buffer window and the working directory isn't changed. I have this code in the fm-nvim config

local chg_cwd = function()
  local cwd = io.open('/tmp/fm-nvim', 'r')
  io.input(cwd)
  local pwd = io.read()
  vim.api.nvim_command('cd ' .. pwd)
  os.remove(cwd)
end

require('fm-nvim').setup {
  cmds = {
    xplr_cmd = 'xplr --print-pwd-as-result',
  },
  on_close = {
    chg_cwd,
  },
}

Is there an issue with this config?

@is0n
Copy link
Owner

is0n commented Feb 12, 2022

Try this out...

local function chg_cwd()
    local file = vim.fn.readfile("/tmp/fm-nvim")[1]
    if vim.fn.isdirectory(file) == 1 then
        vim.cmd("cd " .. file)
        os.remove("/tmp/fm-nvim")
    end
end

require('fm-nvim').setup {
  on_close = {
    chg_cwd,
  }
}

Note that including --print-pwd-as-result will prevent this from working (but other args are fine)

You can still open files normally but when a directory is chosen, nvim will cd to that directory.

@ayushnix
Copy link
Author

Hmm, that didn't work for me, pressing enter on a dir still opens it instead of changing the working directory.

Here's the installation of fm-nvim by packer

local cfg = function(name)
  return string.format('require("cfg.%s")', name)
end

return require('packer').startup(function(use)
  use {
    'is0n/fm-nvim',
    config = cfg('fm'),
  }
end)

and here's the config file fm.lua itself

local ok, fm = pcall(require, 'fm-nvim')
if not ok then
  vim.notify('unable to find fm-nvim')
  return
end

local function chg_cwd()
  local file = vim.fn.readfile('/tmp/fm-nvim')[1]
  if vim.fn.isdirectory(file) == 1 then
    vim.cmd('cd ' .. file)
    os.remove('/tmp/fm-nvim')
  end
end

fm.setup {
  ui = {
    default = 'split',
    split = {
      size = 50,
    },
  },
  on_close = {
    chg_cwd,
  },
}

I wasn't sure about the [1] and I removed it but that help either. I've also disabled netrw and I enabled it but just opens up the directory I select in netrw.

@is0n
Copy link
Owner

is0n commented Feb 12, 2022

Are you on the latest version of fm-nvim?

@ayushnix
Copy link
Author

Yeah. I updated fm-nvim to add the latest commit, f75cdf4, but that doesn't help either.

@is0n
Copy link
Owner

is0n commented Feb 12, 2022

This is me using the chg_cwd function and it works for me. I'm not sure what's preventing it from working on your machine.

Untitled.mp4

Here's the my config in case you might help:

local function chg_cwd()
    local file = vim.fn.readfile("/tmp/fm-nvim")[1]
    if vim.fn.isdirectory(file) == 1 then
        vim.cmd("cd " .. file)
        os.remove("/tmp/fm-nvim")
    end
end

require('fm-nvim').setup{
	ui = {
		default = "float",
		float = {
			border   = "single",
			border_hl = "NONE",
		},
	},
	cmds = {
		fzf_cmd = "fzf --preview 'fzf-preview {}' -1 -m",
	},
	on_close = {
		chg_cwd,
	}
}

This is the output of nvim -v:

NVIM v0.6.1
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by brew@iMac-Pro

From what I can tell, the problem isn't with the chg_cwd function but rather something with your config.

@Giles-Aiden
Copy link

Giles-Aiden commented Sep 5, 2022

@is0n while what you are doing is definitely changing the directory, I believe the intended behavior @ayushnix wanted is to change the directory in xplr, not vim. This solution results in a flicker but gets the job done. The problem with this solution is that every time you hit enter to on a folder, you have to reenter insert mode with i.

local function chg_cwd()
  local file = vim.fn.readfile("/tmp/fm-nvim")[1]
  if vim.fn.isdirectory(file) == 1 then
    vim.cmd.Xplr(file)
    os.remove("/tmp/fm-nvim")
  end
end

require('fm-nvim').setup {
  on_close = {
    chg_cwd,
  },
}

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

No branches or pull requests

3 participants