added git commits,bcommits,branches

main
bhagwan 3 years ago
parent 049298e818
commit 1257eadb7c

@ -120,7 +120,6 @@ nnoremap <c-P> <cmd>lua require('fzf-lua').files()<CR>
| --- | --- |
|`buffers`|open buffers|
|`files`|`find` or `fd` on a path|
|`git_files`|`git ls-files`|
|`oldfiles`|opened files history|
|`quickfix`|quickfix list|
|`loclist`|location list|
@ -135,6 +134,10 @@ nnoremap <c-P> <cmd>lua require('fzf-lua').files()<CR>
|`man_pages`|man pages|
|`colorschemes`|color schemes|
|`builtin`|fzf-lua builtin methods|
|`git_files`|`git ls-files`|
|`git_commits`|git commit log (project)|
|`git_bcommits`|git commit log (buffer)|
|`git_branch`|git branches|
## LSP Commands
@ -239,11 +242,37 @@ require'fzf-lua'.setup {
}
},
git = {
prompt = 'GitFiles ',
cmd = 'git ls-files --exclude-standard',
git_icons = true, -- show git icons?
file_icons = true, -- show file icons?
color_icons = true, -- colorize file|git icons
files = {
prompt = 'GitFiles ',
cmd = 'git ls-files --exclude-standard',
git_icons = true, -- show git icons?
file_icons = true, -- show file icons?
color_icons = true, -- colorize file|git icons
},
commits = {
prompt = 'Commits ',
cmd = "git log --pretty=oneline --abbrev-commit --color",
preview = "git show --pretty='%Cred%H%n%Cblue%an%n%Cgreen%s' --color {1}",
actions = {
["default"] = nil,
},
},
bcommits = {
prompt = 'BCommits ',
cmd = "git log --pretty=oneline --abbrev-commit --color --",
preview = "git show --pretty='%Cred%H%n%Cblue%an%n%Cgreen%s' --color {1}",
actions = {
["default"] = nil,
},
},
branches = {
prompt = 'Branches ',
cmd = "git branch --all --color",
preview = "git log --graph --pretty=oneline --abbrev-commit --color {1}",
actions = {
["default"] = actions.git_switch,
},
},
icons = {
["M"] = { icon = "M", color = "yellow" },
["D"] = { icon = "D", color = "red" },
@ -363,8 +392,8 @@ EOF
- Add more providers
+ [x] ~~LSP (refs, symbols, etc)~~ (2021-07-20)
+ [ ] git commits
+ [ ] git branches
+ [x] ~~git commits~~ (2021-08-05)
+ [x] ~~git branches~~ (2021-08-05)
+ [ ] vim commands
+ [ ] vim command history
+ [ ] vim keymaps

@ -1,3 +1,5 @@
local utils = require "fzf-lua.utils"
local M = {}
-- return fzf '--expect=' string from actions keyval tbl
@ -160,4 +162,20 @@ M.man_tab = function(selected)
M.vimcmd(vimcmd, selected)
end
M.git_switch = function(selected)
-- remove anything past space
local branch = selected[1]:match("[^ ]+")
-- do nothing for active branch
if branch:find("%*") ~= nil then return end
local args = ""
if branch:find("/") ~= nil then args = "--detach " end
local output = vim.fn.systemlist("git switch " .. args .. branch)
if utils.shell_error() then
utils.err(unpack(output))
else
utils.info(unpack(output))
vim.cmd("edit!")
end
end
return M

@ -123,17 +123,43 @@ M.globals = {
-- Must construct our opts table in stages
-- so we can reference 'M.globals.files'
M.globals.git = {
prompt = 'GitFiles> ',
cmd = "git ls-files --exclude-standard",
file_icons = true and M._has_devicons,
color_icons = true,
git_icons = true,
actions = M.globals.files.actions,
files = {
prompt = 'GitFiles> ',
cmd = "git ls-files --exclude-standard",
file_icons = true and M._has_devicons,
color_icons = true,
git_icons = true,
actions = M.globals.files.actions,
},
commits = {
prompt = 'Commits> ',
cmd = "git log --pretty=oneline --abbrev-commit --color",
preview = "git show --pretty='%Cred%H%n%Cblue%an%n%Cgreen%s' --color {1}",
actions = {
["default"] = nil,
},
},
bcommits = {
prompt = 'BCommits> ',
cmd = "git log --pretty=oneline --abbrev-commit --color --",
preview = "git show --pretty='%Cred%H%n%Cblue%an%n%Cgreen%s' --color {1}",
actions = {
["default"] = nil,
},
},
branches = {
prompt = 'Branches> ',
cmd = "git branch --all --color",
preview = "git log --graph --pretty=oneline --abbrev-commit --color {1}",
actions = {
["default"] = actions.git_switch,
},
},
icons = {
["M"] = { icon = "M", color = "yellow" },
["D"] = { icon = "D", color = "red" },
["A"] = { icon = "A", color = "green" },
["?"] = { icon = "?", color = "magenta" },
["M"] = { icon = "M", color = "yellow" },
["D"] = { icon = "D", color = "red" },
["A"] = { icon = "A", color = "green" },
["?"] = { icon = "?", color = "magenta" },
},
}
M.globals.grep = {

@ -16,7 +16,7 @@ M.get_devicon = function(file, ext)
return icon
end
M.build_fzf_cli = function(opts)
M.build_fzf_cli = function(opts, debug_print)
opts.prompt = opts.prompt or config.globals.default_prompt
opts.preview_offset = opts.preview_offset or ''
opts.fzf_bin = opts.fzf_bin or config.globals.fzf_bin
@ -32,7 +32,7 @@ M.build_fzf_cli = function(opts)
vim.fn.shellescape(opts.prompt),
utils._if(opts.preview_window, opts.preview_window, config.preview_window()),
utils._if(#opts.preview_offset>0, ":"..opts.preview_offset, ''),
utils._if(opts.preview, opts.preview, "''"),
utils._if(opts.preview and #opts.preview>0, opts.preview, "''"),
-- HACK: support skim (rust version of fzf)
utils._if(opts.fzf_bin and opts.fzf_bin:find('sk')~=nil, "--inline-info", "--info=inline"),
utils._if(actions.expect(opts.actions), actions.expect(opts.actions), ''),
@ -40,7 +40,7 @@ M.build_fzf_cli = function(opts)
utils._if(opts.fzf_cli_args, opts.fzf_cli_args, ''),
utils._if(opts._fzf_cli_args, opts._fzf_cli_args, '')
)
-- print(cli)
if debug_print then print(cli) end
return cli
end

@ -55,7 +55,10 @@ M.grep_cword = require'fzf-lua.providers.grep'.grep_cword
M.grep_cWORD = require'fzf-lua.providers.grep'.grep_cWORD
M.grep_visual = require'fzf-lua.providers.grep'.grep_visual
M.grep_curbuf = require'fzf-lua.providers.grep'.grep_curbuf
M.git_files = require'fzf-lua.providers.files'.git_files
M.git_files = require'fzf-lua.providers.git'.files
M.git_commits = require'fzf-lua.providers.git'.commits
M.git_bcommits = require'fzf-lua.providers.git'.bcommits
M.git_branches = require'fzf-lua.providers.git'.branches
M.oldfiles = require'fzf-lua.providers.oldfiles'.oldfiles
M.quickfix = require'fzf-lua.providers.quickfix'.quickfix
M.loclist = require'fzf-lua.providers.quickfix'.loclist

@ -46,15 +46,4 @@ M.files = function(opts)
return core.fzf_files(opts)
end
M.git_files = function(opts)
local output = vim.fn.systemlist("git status")
if utils.shell_error() then
utils.info(unpack(output))
return
end
opts = config.normalize_opts(opts, config.globals.git)
-- opts.cmd sets this to "git ls-files"
return M.files(opts)
end
return M

@ -0,0 +1,79 @@
if not pcall(require, "fzf") then
return
end
local fzf = require "fzf"
local fzf_helpers = require("fzf.helpers")
local core = require "fzf-lua.core"
local utils = require "fzf-lua.utils"
local config = require "fzf-lua.config"
local actions = require "fzf-lua.actions"
local M = {}
local function git_status()
local output = vim.fn.systemlist("git status")
if utils.shell_error() then
utils.info(unpack(output))
return false
end
return true
end
M.files = function(opts)
if not git_status() then return end
opts = config.normalize_opts(opts, config.globals.git.files)
opts.fzf_fn = fzf_helpers.cmd_line_transformer(opts.cmd,
function(x)
return core.make_entry_file(opts, x)
end)
return core.fzf_files(opts)
end
local function git_cmd(opts)
if not git_status() then return end
coroutine.wrap(function ()
opts.fzf_fn = fzf_helpers.cmd_line_transformer(opts.cmd,
function(x) return x end)
local selected = fzf.fzf(opts.fzf_fn,
core.build_fzf_cli(opts, false),
config.winopts(opts))
if not selected then return end
actions.act(opts.actions, selected)
end)()
end
M.commits = function(opts)
opts = config.normalize_opts(opts, config.globals.git.commits)
opts.preview = vim.fn.shellescape(opts.preview)
return git_cmd(opts)
end
M.bcommits = function(opts)
opts = config.normalize_opts(opts, config.globals.git.bcommits)
local file = vim.fn.shellescape(vim.fn.expand("%"))
opts.cmd = opts.cmd .. " " .. file
opts.preview = opts.preview .. " --rotate-to=" .. file
opts.preview = vim.fn.shellescape(opts.preview)
return git_cmd(opts)
end
M.branches = function(opts)
opts = config.normalize_opts(opts, config.globals.git.branches)
opts._preview = opts.preview
opts.preview = fzf_helpers.choices_to_shell_cmd_previewer(function(items)
local branch = items[1]:gsub("%*", "") -- remove the * from current branch
if branch:find("%)") ~= nil then
-- (HEAD detached at origin/master)
branch = branch:match(".* ([^%)]+)") or ""
else
-- remove anything past space
branch = branch:match("[^ ]+")
end
return opts._preview:gsub("{.*}", branch)
-- return "echo " .. branch
end)
return git_cmd(opts)
end
return M
Loading…
Cancel
Save