-
-
Notifications
You must be signed in to change notification settings - Fork 136
Open
Labels
enhancementNew feature or requestNew feature or request
Description
I'm seeking to use Neovim as my Git UI.
In the log view, gf
opens the file in Neovim. But I'd like to have another keybind to open files that aren't supported by Neovim, say image files.
I copied some code from
diffview.nvim/lua/diffview/actions.lua
Line 37 in 3dc498c
---@return FileEntry? |
In the following I use go
to open a file with xdg-open
. However as you can see there's a lot of copy paste:
local function goto_file_open()
local lazy = require('diffview.lazy')
local lib = lazy.require('diffview.lib')
local utils = lazy.require('diffview.utils')
local DiffView = lazy.access('diffview.scene.views.diff.diff_view', 'DiffView')
local FileHistoryView = lazy.access('diffview.scene.views.file_history.file_history_view', 'FileHistoryView')
local pl = lazy.access(utils, 'path')
local view = lib.get_current_view()
if view and not (view:instanceof(DiffView.__get()) or view:instanceof(FileHistoryView.__get())) then
return
end
local file = view:infer_cur_file()
if file then
-- Ensure file exists
if not pl:readable(file.absolute_path) then
utils.err(string.format("File does not exist on disk: '%s'", pl:relative(file.absolute_path, '.')))
return
end
vim.fn.jobstart({ 'xdg-open', file.absolute_path })
end
end
return {
'sindrets/diffview.nvim',
event = 'VeryLazy',
opts = {
enhanced_diff_hl = true,
keymaps = {
view = {
{ 'n', 'go', goto_file_open },
},
file_panel = {
{ 'n', 'go', goto_file_open },
},
file_history_panel = {
{ 'n', 'go', goto_file_open },
},
},
},
...
}
Could you expose prepare_goto_file()
? And add this too if this seems good.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request