From 5722fd62fd737392eae2c3aa1fb103629d7bd564 Mon Sep 17 00:00:00 2001 From: bhagwan Date: Fri, 22 Apr 2022 09:57:08 -0700 Subject: [PATCH] feat(git_diff): more complex custom preview commands (closes #392) --- lua/fzf-lua/previewer/fzf.lua | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lua/fzf-lua/previewer/fzf.lua b/lua/fzf-lua/previewer/fzf.lua index 80dd3a9..378664c 100644 --- a/lua/fzf-lua/previewer/fzf.lua +++ b/lua/fzf-lua/previewer/fzf.lua @@ -284,8 +284,19 @@ function Previewer.git_diff:cmdline(o) vim.fn.executable(self.pager:match("[^%s]+")) == 1 then pager = '| ' .. self.pager end - cmd = string.format('FZF_PREVIEW_LINES=%d;FZF_PREVIEW_COLUMNS=%d;%s %s %s', - fzf_lines, fzf_columns, cmd, vim.fn.shellescape(file.path), pager) + -- with default commands we add the filepath at the end + -- if the user configured a more complex command, e.g.: + -- git_diff = { + -- cmd_modified = "git diff --color HEAD %s | less -SEX" + -- } + -- we use ':format' directly on the user's command, see + -- issue #392 for more info (limiting diff output width) + if not cmd:match("%%s") then + cmd = cmd .. " %s" + end + cmd = cmd:format(vim.fn.shellescape(file.path)) + cmd = ("FZF_PREVIEW_LINES=%d;FZF_PREVIEW_COLUMNS=%d;%s %s") + :format(fzf_lines, fzf_columns, cmd, pager) cmd = 'sh -c ' .. vim.fn.shellescape(cmd) if self.opts.debug then print("[DEBUG]: "..cmd.."\n")