git_branches remove --reflog, minor previewer interfaces changes

main
bhagwan 3 years ago
parent 2016be182a
commit 01e79fd8c9

@ -357,7 +357,7 @@ require'fzf-lua'.setup {
branches = {
prompt = 'Branches ',
cmd = "git branch --all --color",
preview = "git log --graph --pretty=oneline --abbrev-commit --reflog --color {1}",
preview = "git log --graph --pretty=oneline --abbrev-commit --color {1}",
actions = {
["default"] = actions.git_switch,
},

@ -193,7 +193,7 @@ M.globals.git = {
branches = {
prompt = 'Branches> ',
cmd = "git branch --all --color",
preview = "git log --graph --pretty=oneline --abbrev-commit --reflog --color {1}",
preview = "git log --graph --pretty=oneline --abbrev-commit --color {1}",
actions = {
["default"] = actions.git_switch,
},

@ -4,31 +4,30 @@ local utils = require "fzf-lua.utils"
local config = require "fzf-lua.config"
local actions = require "fzf-lua.actions"
local win = require "fzf-lua.win"
local string_byte = string.byte
local string_byte_a = string_byte("a")
local string_byte_z = string_byte("z")
local M = {}
M.fzf = function(opts, contents, previewer)
M.fzf = function(opts, contents)
-- setup the fzf window and preview layout
local fzf_win = win(opts)
-- instantiate the previewer
-- if not opts.preview and not previewer and
if not previewer and
opts.previewer and type(opts.previewer) == 'string' then
local preview_opts = config.globals.previewers[opts.previewer]
if preview_opts then
previewer = preview_opts._new()(preview_opts, opts, fzf_win)
opts.preview = previewer:cmdline()
if type(previewer.override_fzf_preview_window) == 'function' then
-- do we need to override the preview_window args?
-- this can happen with the builtin previewer
-- (1) when using a split we use the previewer as placeholder
-- (2) we use 'right:0' to call the previewer function only
if previewer:override_fzf_preview_window() then
opts.preview_window = previewer:preview_window()
end
local previewer, preview_opts = nil, nil
if opts.previewer and type(opts.previewer) == 'string' then
preview_opts = config.globals.previewers[opts.previewer]
elseif opts.previewer and type(opts.previewer) == 'table' then
preview_opts = opts.previewer
end
if preview_opts then
previewer = preview_opts._new()(preview_opts, opts, fzf_win)
opts.preview = previewer:cmdline()
if type(previewer.override_fzf_preview_window) == 'function' then
-- do we need to override the preview_window args?
-- this can happen with the builtin previewer
-- (1) when using a split we use the previewer as placeholder
-- (2) we use 'right:0' to call the previewer function only
if previewer:override_fzf_preview_window() then
opts.preview_window = previewer:preview_window()
end
end
end
@ -41,21 +40,10 @@ M.fzf = function(opts, contents, previewer)
return selected
end
local function char_is_lower(str, idx)
local byte = string_byte(str, idx)
return byte >= string_byte_a and byte <= string_byte_z
end
M.get_devicon = function(file, ext)
local icon, hl
if config._has_devicons and config._devicons then
icon, hl = config._devicons.get_icon(file, ext:lower(), {default = true})
--[[ if hl and #hl>7 and char_is_lower(hl, 8) then
-- workaround for issue #119, devicons returns
-- highlights with lowercase icon names
-- (i.e. DevIconpy instead of DevIconPy)
hl = hl:sub(1,7) .. hl:sub(8,8):upper() .. hl:sub(9)
end ]]
else
icon, hl = '', 'dark_grey'
end

@ -29,6 +29,7 @@ function Previewer.base:new(o, opts)
self.type = "cmd";
self.cmd = o.cmd;
self.args = o.args or "";
self.relative = o.relative
self.opts = opts;
return self
end
@ -57,7 +58,7 @@ function Previewer.cmd:action(o)
end
local act = raw_action(function (items, fzf_lines, _)
-- only preview first item
local file = path.entry_to_file(items[1], self.opts.cwd)
local file = path.entry_to_file(items[1], not self.relative and self.opts.cwd)
return file.path
end, filespec)
return act
@ -117,8 +118,8 @@ end
function Previewer.cmd_async:cmdline(o)
o = o or {}
local act = helpers.choices_to_shell_cmd_previewer(function(items)
local file = path.entry_to_file(items[1], self.opts.cwd)
local cmd = string.format('%s %s "%s"', self.cmd, self.args, file.path)
local file = path.entry_to_file(items[1], not self.relative and self.opts.cwd)
local cmd = string.format('%s %s %s', self.cmd, self.args, vim.fn.shellescape(file.path))
-- uncomment to see the command in the preview window
-- cmd = vim.fn.shellescape(cmd)
return cmd
@ -142,7 +143,7 @@ function Previewer.bat_async:cmdline(o)
highlight_line = string.format("--highlight-line=", self.opts._line_placeholder)
end
local act = helpers.choices_to_shell_cmd_previewer(function(items)
local file = path.entry_to_file(items[1], self.opts.cwd)
local file = path.entry_to_file(items[1], not self.relative and self.opts.cwd)
local cmd = string.format('%s %s %s%s "%s"',
self.cmd, self.args,
highlight_line,
@ -169,7 +170,7 @@ function Previewer.git_diff:cmdline(o)
local act = helpers.choices_to_shell_cmd_previewer(function(items)
local is_deleted = items[1]:match("D"..utils.nbsp) ~= nil
local is_untracked = items[1]:match("?"..utils.nbsp) ~= nil
local file = path.entry_to_file(items[1], self.opts.cwd)
local file = path.entry_to_file(items[1], not self.relative and self.opts.cwd)
local cmd = self.cmd
local args = self.args
if is_untracked then args = args .. " --no-index /dev/null" end
@ -177,7 +178,7 @@ function Previewer.git_diff:cmdline(o)
cmd = self.cmd:gsub("diff", "show HEAD:")
cmd = string.format('%s"%s"', cmd, path.relative(file.path, self.opts.cwd))
else
cmd = string.format('%s %s "%s"', cmd, args, file.path)
cmd = string.format('%s %s %s', cmd, args, vim.fn.shellescape(file.path))
end
-- uncomment to see the command in the preview window
-- cmd = vim.fn.shellescape(cmd)

Loading…
Cancel
Save