otavioschwanck / arrow.nvim

Bookmark your files, separated by project, and quickly navigate through them.
Other
341 stars 16 forks source link

Feature request: save bookmarks based on git root #21

Closed sQVe closed 4 months ago

sQVe commented 4 months ago

Hey, 👋

I have a feature request that would immensely improve my workflow. I primarily work in large monorepos and often open subdirectories within a repository to make things easier to find. However, this is a bit awkward when using arrow.nvim, as it doesn't resolve my bookmarks based on the git repository but rather on the current working directory.

It would be great if we could be provided with an option on how we want to resolve the working directory that arrow will associate the bookmarks with. That way, I could execute a command like git rev-parse --show-toplevel to get the path of the git repository.

🍻

otavioschwanck commented 4 months ago

Done here:

https://github.com/otavioschwanck/arrow.nvim/commit/da413d8d3c5e90f51e08ba81e77b516916b87f3b

just add save_key = "git_root" to the setup

sQVe commented 4 months ago

@otavioschwanck There's an issue with this implementation. When enabling this option, and going into sub directories of the repository, and bookmarking a file, the path to the file relates to the sub direcotry rather than the git_root.

otavioschwanck commented 4 months ago

@otavioschwanck There's an issue with this implementation. When enabling this option, and going into sub directories of the repository, and bookmarking a file, the path to the file relates to the sub direcotry rather than the git_root.

I am using the git rev-parse --show-toplevel | tr -d '\n' to get the git root.

What command should i use to get the real root when you are on the file dir?

sQVe commented 4 months ago

I am using the git rev-parse --show-toplevel | tr -d '\n' to get the git root.

That command should be sufficient to retrieve the true path to the root Git directory.


I would assume that the fix you implemented pertains only to the repository matching, i.e. _home_sqve_code_notebox.nvim-main, since I'm now receiving the correct bookmarks when entering subdirectories.

However, the paths saved within _home_sqve_code_notebox.nvim-main are still relative to the current cwd, rather than to the git_root.

If I'm in ~/code/notebox.nvim/lua/notebox and bookmark a file there, it creates a _home_sqve_code_notebox.nvim-main file with the following content:

init.lua
otavioschwanck commented 4 months ago

I am using the git rev-parse --show-toplevel | tr -d '\n' to get the git root.

That command should be sufficient to retrieve the true path to the root Git directory.

I would assume that the fix you implemented pertains only to the repository matching, i.e. _home_sqve_code_notebox.nvim-main, since I'm now receiving the correct bookmarks when entering subdirectories.

However, the paths saved within _home_sqve_code_notebox.nvim-main are still relative to the current cwd, rather than to the git_root.

If I'm in ~/code/notebox.nvim/lua/notebox and bookmark a file there, it creates a _home_sqve_code_notebox.nvim-main file with the following content:

init.lua

any idea how could i get the correct git_root inside notebox?

sQVe commented 4 months ago

any idea how could i get the correct git_root inside notebox?

A simple solution would be to get the absolute path of the current buffer with vim.fn.expand('%:p') and then remove the git root path from the beginning of that path.

There needs to be some kind of fallback for when you're in a directory that isn't a repository though.

sQVe commented 4 months ago

@otavioschwanck I'm working on a PR to add this feature fully. 👍