robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Tomas Slusnyfix(startup): use `nvim.difftool` for `nvim -d` only for directories #401852fd2361a9d

master
921 B36 linesraw
1if vim.g.loaded_difftool ~= nil then
2  return
3end
4vim.g.loaded_difftool = true
5
6vim.api.nvim_create_user_command('DiffTool', function(opts)
7  if #opts.fargs == 2 then
8    require('difftool').open(opts.fargs[1], opts.fargs[2])
9  else
10    vim.notify('Usage: DiffTool <left> <right>', vim.log.levels.ERROR)
11  end
12end, { nargs = '*', complete = 'file' })
13
14-- If we are in diff mode (e.g. `nvim -d file1 file2`), open the difftool automatically.
15local function start_diff()
16  if not vim.o.diff then
17    return
18  end
19  local args = vim.v.argf
20  if #args == 2 then
21    local left = args[1]
22    local right = args[2]
23    if vim.fn.isdirectory(left) == 1 and vim.fn.isdirectory(right) == 1 then
24      vim.schedule(function()
25        require('difftool').open(left, right)
26      end)
27    end
28  end
29end
30if vim.v.vim_did_enter > 0 then
31  start_diff()
32  return
33end
34vim.api.nvim_create_autocmd('VimEnter', {
35  callback = start_diff,
36})