-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
Question: Working with fzf-lua's bcommit #237
Comments
I could add an option, for example (something like this): require("gitlinker").setup({
filename_formatter = function(bufnr, git_root_dir)
local bufname = vim.api.nvim_buf_get_name(bufnr)
local rel_filename = get relative path of `bufname` based on `git_root_dir`
return rel_filename
end
}) By default, the But for your use case, you can overwrite the default configs with: --- @param src The string value
--- @param target The `target` string to be found
--- @return integer? The `target` string index been found in `src`
local function string_find(src, target)
...
end
require("gitlinker").setup({
filename_formatter = function(bufnr)
local bufname = vim.api.nvim_buf_get_name(bufnr)
local filename_end_pos = string_find(bufname, '[')
if type(filename_end_pos) == 'number' and filename_end_pos > 0 then
return string.sub(bufname, 1, filename_end_pos-1)
else
-- for other cases, still use the old method
local rel_filename = get relative path of `bufname` based on `git_root_dir`
return rel_filename
end
end
}) Does that look good for your use case? |
Hi @linrongbin16 . Thank you for such a quick response! That does look good to me for this case! To confirm this will still be running |
oh......., It seems cannot use the commit ID from fzf-lua's bcommit result, unless we add 1 more parameter (for example) |
RFC about these 2 parameters
Note: these 2 parameters will be add to both user command So you can use with either:
Once done, you should be able to define a key mapping like this: --- @param s The string value to be find
--- @param c The target string to find
--- @return integer? The first index of target `c` been found in `s`, return `nil` if not found
local function string_find(s, c)
-- implement find function
end
local function file_on_bcommit()
local bufnr = vim.api.nvim_get_current_buf()
local bufname = vim.api.nvim_buf_get_name()
local first_left_bracket_pos = string_find(bufname, '[')
if type(first_left_bracket_pos) == 'number' and first_left_bracket_pos > 0 then
local relpath = string.sub(bufname, 1, first_left_bracket_pos-1)
return relpath
end
-- return nil, this plugin will use the default generated file path
return nil
end
local function rev_on_bcommit()
local bufnr = vim.api.nvim_get_current_buf()
local bufname = vim.api.nvim_buf_get_name()
local first_left_bracket_pos = string_find(bufname, '[')
if type(first_left_bracket_pos) == 'number' and first_left_bracket_pos > 0 then
local rev = string.sub(bufname, first_left_bracket_pos+1, string.len(bufname)-1)
return rev
end
-- return nil, so this plugin will use the default generated commit ID
return nil
end
vim.keymap.set(
{"n", 'v'},
"<leader>gF",
function()
require("gitlinker").link({
file = file_on_bcommit(),
rev = rev_on_bcommit(),
})
end,
{ silent = true, noremap = true, desc = "GitLink on fzf-lua bcommit" }
) |
Oo this is interesting. I think that should work. I think I'll also wrap That way, there's only one keybind I need to remember and it should work for both cases. |
hi @hqkhan , New feature is merged into master, have a try! You can use something like |
Awesome! Ty! Will be trying soon and I'll post back here with results :D |
Hi @linrongbin16. I may be missing something but the path checker is still causing issues.
In the case of |
Hi @linrongbin16. It's working! I just need to parse the file name better but other than that, it looks good from GitLinker's side as far as I can tell. |
Wanted to post my final working solution that I've tested.
Might have some rough edges that I'll find out about later on but overall, it's working nicely. Thanks again for your help :) |
Details
This is more about asking for guidance on how I can make gitlinker work with fzf-lua's
bcommit
. Withbcommit
, I can open a file in a new buffer at the selected commit. This newly created buffer has the following naming format:<file_name>[commit_hash]
. Example:editorconfig[7ac8301]
.This doesn't work currently as we don't move commits or change branches from wherever we're at. It simply opens a new buffer with changes from that commit.
Now, if gitlinker went through all the checks auto-magically and put me in my router function, I can do a check to see if the name follows the naming format described above and create my URL accordingly. However, we run into an error that the file (newly created buffer) doesn't exist in the commit which makes sense. I've provided my config and error message below from log file.
I wanted to ask if there's a way for me to bypass this check of
git cat-file -e <commit_hash>:<file_name>
. The rest of the info gathering git calls can remain as I've already specified a remote in my keybind (see below). If I can get to my router function, I should be able to get it to work.Config
Error
The text was updated successfully, but these errors were encountered: