junegunn / junegunn/gv.vim

Expose file path via buffer variable for GV! (file-specific log)

Open
#120 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Vim Script
Stars
1.4k
Forks
55
PR merge metrics
No merged PRs in 30d

Description

When GV! opens a file-specific log, consumers currently have no API to retrieve which file the log is for. The only way is to parse the buffer name (repo --follow -- path/to/file), which is fragile and undocumented.

Request: Set a buffer variable like b:gv_path (the file path relative to the repo root) when GV! creates the log buffer. This would be analogous to how fugitive exposes b:fugitive_blamed_bufnr in blame buffers.

Use case: Building a keymap that diffs a selected commit against the working file. Today this requires:

-- Fragile: parses GV's internal buffer name format
local file = vim.api.nvim_buf_get_name(0):match('%-%- (.+)$')

With b:gv_path:

local file = vim.b.gv_path -- nil if not a file-specific log

Suggested change (one line in s:list()):

" After line 221 (setf GV):
if a:log_opts[-1] =~# '^--$' || (len(a:log_opts) > 1 && a:log_opts[-2] ==# '--')
let b:gv_path = a:log_opts[-1] ==# '--' ? '' : a:log_opts[-1]
endif

Or more simply, pass the path from s:gv() where current is already known.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.