GithubHelp home page GithubHelp logo

Comments (6)

is0n avatar is0n commented on July 4, 2024

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.

from fm-nvim.

ayushnix avatar ayushnix commented on July 4, 2024

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.

from fm-nvim.

is0n avatar is0n commented on July 4, 2024

Are you on the latest version of fm-nvim?

from fm-nvim.

ayushnix avatar ayushnix commented on July 4, 2024

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

from fm-nvim.

is0n avatar is0n commented on July 4, 2024

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.

from fm-nvim.

Giles-Aiden avatar Giles-Aiden commented on July 4, 2024

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

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.