Skip to content

Provide information about renamed files for editor integrations #766

@mikavilpas

Description

@mikavilpas

Please describe the problem you're trying to solve

Hi! I am working on a neovim integration at https://github.com/mikavilpas/yazi.nvim.

It opens yazi in a floating terminal and then returns to neovim once yazi has been closed.
It works nicely for simple cases, but sometimes if I rename files or directories, neovim doesn't know about these changes and still has the old file path open.

Would you be willing to contribute this feature?

  • Yes, I'll give it a shot

Describe the solution you'd like

Proposition: Write information about the renamings into a file on exit

Currently yazi has the --chooser-file option which will contain the chosen files after yazi has exited.

Do you think adding a new option like --renamed-files could work? It could be similar but for files that were renamed, and could contain a list of renaming operations like so:

// note: the file doesn't necessarily have to be json, but a structured format
// of some kind would eliminate the need for writing extra parsing logic
[
  // example 1: the first renaming operation in the yazi session
  // (the user can do many renaming operations in a single session)
  {
    // this indicates a file was renamed to another file
    "/home/user/project/file_A": "/home/user/project/file_BBBBB",
    // the editor integration can use this information to update the buffer
    // path in the editor
  },

  // example 2: renaming a directory
  {
    "/home/user/project/dir1": "/home/user/project/dir2",
    // the editor integration can update the file paths for all buffers that
    // are open for files in the directory
  },

  // example 3: moving a file into a directory
  {
    "/home/user/project/file_BBBBB": "/home/user/project/dir1/file_BBBBB",
  },
  
  // example 4: moving a directory into another directory
  {
    "/home/user/project/dir1": "/home/user/project/dir2/dir1",
  },
]

The editor integration could read this file in after yazi has exited, and update its knowledge about the buffers' files in the same order that yazi did. This should give reasonable guarantees that the editor now tracks the correct file paths.

Additional context

If you think this approach could work, I would like to give this a shot myself.

I'm not experienced in rust beyond a few advent of code problems that I did last summer out of interest, but this solution seems quite simple because similar functionality already exists 🤞🏻

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions