From 01e79fd8c9d96310bb3b90abd53c6394aba204a0 Mon Sep 17 00:00:00 2001 From: bhagwan Date: Wed, 8 Sep 2021 14:54:27 -0700 Subject: [PATCH] git_branches remove --reflog, minor previewer interfaces changes --- README.md | 2 +- lua/fzf-lua/config.lua | 2 +- lua/fzf-lua/core.lua | 46 +++++++++++++--------------------- lua/fzf-lua/previewer/init.lua | 13 +++++----- 4 files changed, 26 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 0380d36..2e8c697 100644 --- a/README.md +++ b/README.md @@ -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, }, diff --git a/lua/fzf-lua/config.lua b/lua/fzf-lua/config.lua index 87be77c..f4dd405 100644 --- a/lua/fzf-lua/config.lua +++ b/lua/fzf-lua/config.lua @@ -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, }, diff --git a/lua/fzf-lua/core.lua b/lua/fzf-lua/core.lua index a730004..088c8f5 100644 --- a/lua/fzf-lua/core.lua +++ b/lua/fzf-lua/core.lua @@ -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 diff --git a/lua/fzf-lua/previewer/init.lua b/lua/fzf-lua/previewer/init.lua index 1e24dcf..a7272e8 100644 --- a/lua/fzf-lua/previewer/init.lua +++ b/lua/fzf-lua/previewer/init.lua @@ -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)