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

yazi.nvim integration #46

Closed
yuvals1 opened this issue Sep 19, 2024 · 7 comments
Closed

yazi.nvim integration #46

yuvals1 opened this issue Sep 19, 2024 · 7 comments

Comments

@yuvals1
Copy link

yuvals1 commented Sep 19, 2024

I'm primarily using yazi.nvim as my file explorer. Is there a way to integrate pymple.nvim with it for automatic import updates?
Could you point me to what would be needed to achieve this integration, either from pymple.nvim's side or yazi.nvim's?

@alexpasmantier
Copy link
Owner

You would need to add the appropriate hooks in this file https://github.com/alexpasmantier/pymple.nvim/blob/main/lua/pymple/hooks.lua#L53-L71

I'm not sure yazi.nvim actually provides hooks for file rename/move operations at the moment though 🤔 but maybe I'm wrong. Will check later today or maybe tomorrow if I get a moment to do so.

@mikavilpas
Copy link

yazi.nvim now publishes events (autocmds) when files are moved or renamed 🙂

mikavilpas/yazi.nvim#493 (reply in thread)

@alexpasmantier
Copy link
Owner

Hi, thanks for adding the feature.
Just tried it and it seems I can't detect any events when renaming or moving files with Yazi, even when setting up your example snippet.
Any idea why that might be?

I'm not sure the logs are of any help here but pasting them just in case:

  2024-10-04T21:07:49.630258Z  WARN yazi_adapter::adapter: [Adapter] Could not identify XDG_SESSION_TYPE
    at yazi-adapter/src/adapter.rs:108

  2024-10-04T21:07:49.630291Z  WARN yazi_adapter::adapter: [Adapter] Falling back to chafa
    at yazi-adapter/src/adapter.rs:120

  2024-10-04T21:07:49.631212Z  WARN yazi_adapter::ueberzug: ueberzugpp spawning failed: No such file or directory (os error 2)
    at yazi-adapter/src/ueberzug.rs:95

  2024-10-04T21:08:39.085508Z  WARN yazi_adapter::adapter: [Adapter] Could not identify XDG_SESSION_TYPE
    at yazi-adapter/src/adapter.rs:108

  2024-10-04T21:08:39.085530Z  WARN yazi_adapter::adapter: [Adapter] Falling back to chafa
    at yazi-adapter/src/adapter.rs:120

  2024-10-04T21:08:39.086419Z  WARN yazi_adapter::ueberzug: ueberzugpp spawning failed: No such file or directory (os error 2)
    at yazi-adapter/src/ueberzug.rs:95

@mikavilpas
Copy link

Hmm there's some trouble that I can reproduce. I'll fix it and will let you know when it works, sorry about the trouble 🙂

@mikavilpas
Copy link

Ok, there was a bug - my bad!

It should now be fixed. I was able to use an autocmd (event handler) like this in the integration tests

vim.api.nvim_create_autocmd("User", {
  pattern = "YaziRenamedOrMoved",
  ---@param event {data: YaziNeovimEvent.YaziRenamedOrMovedData}
  callback = function(event)
    -- printing the messages will allow seeing them with `:messages`
    print(
      vim.inspect({ "Just received a YaziRenamedOrMoved event!", event.data })
    )
  end,
})

Can you try this out on the latest version?

@mikavilpas
Copy link

Here is a reproduction script (run with nvim -u repro.lua):

Details

-- You can use this file to reproduce an issue with your configuration.

---@module "yazi"
---@module "lazy"

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "https://github.com/folke/lazy.nvim.git",
    lazypath,
  })
end
vim.opt.runtimepath:prepend(lazypath)
vim.g.mapleader = " "

-- install the following plugins
---@type LazySpec
local plugins = {
  { "catppuccin/nvim", name = "catppuccin", opts = { flavour = "macchiato" } },
  {
    "mikavilpas/yazi.nvim",
    event = "VeryLazy",
    keys = {
      {
        "<leader>-",
        "<cmd>Yazi<cr>",
        desc = "Open yazi at the current file",
      },
      {
        -- Open in the current working directory
        "<leader>cw",
        "<cmd>Yazi cwd<cr>",
        desc = "Open the file manager in nvim's working directory",
      },
      {
        -- NOTE: this requires a version of yazi that includes
        -- https://github.com/sxyazi/yazi/pull/1305 from 2024-07-18
        "<c-up>",
        "<cmd>Yazi toggle<cr>",
        desc = "Resume the last yazi session",
      },
    },
    ---@type YaziConfig
    opts = {
      open_for_directories = false,
    },
  },
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
  install = { colorscheme = { "catppuccin" } },
})

vim.cmd.colorscheme("catppuccin")
-- add anything else here

vim.api.nvim_create_autocmd("User", {
  pattern = "YaziRenamedOrMoved",
  callback = function(event)
    print(
      vim.inspect({ "Just received a YaziRenamedOrMoved event!", event.data })
    )
  end,
})

What you can do is

  • run it with the command above
  • space - (dash) to open yazi. yazi should be shown in a floating window
  • use jk to move to a file you want to rename
  • r to rename
  • finally, q to quit yazi and close the floating window
  • :messages to see the message

@alexpasmantier
Copy link
Owner

Thanks, your fix worked like a charm 🙏🏻

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