Files
neovim/runtime/pack/dist/opt/nvim.difftool/plugin/difftool.lua
Tomas Slusny 2fd2361a9d fix(startup): use nvim.difftool for nvim -d only for directories #40185
Problem:
`nvim -u NONE -d <(xxd one) <(xxd two)` has weird behavior.
Process substitution `<(...)` is a pipe and not a seekable file.

Test case:

    cat /dev/random | head -c 10240 > one 
    cp one two
    cat /dev/random | head -c 10240 >> two
    nvim -u NONE -d <(xxd one) <(xxd two)

Solution:
Workaround the issue by skipping `nvim.difftool` if the 2 args are not
directories; fall-through to the builtin diff handling.

Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
2026-06-11 06:15:04 -04:00

37 lines
921 B
Lua

if vim.g.loaded_difftool ~= nil then
return
end
vim.g.loaded_difftool = true
vim.api.nvim_create_user_command('DiffTool', function(opts)
if #opts.fargs == 2 then
require('difftool').open(opts.fargs[1], opts.fargs[2])
else
vim.notify('Usage: DiffTool <left> <right>', vim.log.levels.ERROR)
end
end, { nargs = '*', complete = 'file' })
-- If we are in diff mode (e.g. `nvim -d file1 file2`), open the difftool automatically.
local function start_diff()
if not vim.o.diff then
return
end
local args = vim.v.argf
if #args == 2 then
local left = args[1]
local right = args[2]
if vim.fn.isdirectory(left) == 1 and vim.fn.isdirectory(right) == 1 then
vim.schedule(function()
require('difftool').open(left, right)
end)
end
end
end
if vim.v.vim_did_enter > 0 then
start_diff()
return
end
vim.api.nvim_create_autocmd('VimEnter', {
callback = start_diff,
})