added 'args' provider

main
bhagwan 3 years ago
parent 67163f4c5f
commit cc74396e8f

@ -137,6 +137,7 @@ vim.api.nvim_set_keymap('n', '<c-P>',
| `lines` | open buffers lines |
| `blines` | current buffer lines |
| `tabs` | open tabs |
| `args` | argument list |
### Search
| Command | List |
@ -345,7 +346,7 @@ require'fzf-lua'.setup {
["ctrl-t"] = actions.file_tabedit,
["alt-q"] = actions.file_sel_to_qf,
-- custom actions are available too
["ctrl-y"] = function(selected) print(selected[2]) end,
["ctrl-y"] = function(selected) print(selected[1]) end,
}
},
git = {
@ -411,6 +412,13 @@ require'fzf-lua'.setup {
file_icons = true, -- show file icons?
color_icons = true, -- colorize file|git icons
},
args = {
prompt = 'Args ',
actions = {
-- added on top of regular file actions
["ctrl-x"] = actions.arg_del,
}
},
oldfiles = {
prompt = 'History ',
cwd_only = false,
@ -444,7 +452,7 @@ require'fzf-lua'.setup {
live_preview = true, -- apply the colorscheme on preview?
actions = {
["default"] = actions.colorscheme,
["ctrl-y"] = function(selected) print(selected[2]) end,
["ctrl-y"] = function(selected) print(selected[1]) end,
},
winopts = {
win_height = 0.55,

@ -160,6 +160,7 @@ BUFFERS AND FILES *fzf-lua-buffers-and-files*
| `lines` | open buffers lines |
| `blines` | current buffer lines |
| `tabs` | open tabs |
| `args` | argument list |
SEARCH *fzf-lua-search*
@ -379,7 +380,7 @@ Consult the list below for available settings:
["ctrl-t"] = actions.file_tabedit,
["alt-q"] = actions.file_sel_to_qf,
-- custom actions are available too
["ctrl-y"] = function(selected) print(selected[2]) end,
["ctrl-y"] = function(selected) print(selected[1]) end,
}
},
git = {
@ -445,6 +446,13 @@ Consult the list below for available settings:
file_icons = true, -- show file icons?
color_icons = true, -- colorize file|git icons
},
args = {
prompt = 'Args ',
actions = {
-- added on top of regular file actions
["ctrl-x"] = actions.arg_del,
}
},
oldfiles = {
prompt = 'History ',
cwd_only = false,
@ -478,7 +486,7 @@ Consult the list below for available settings:
live_preview = true, -- apply the colorscheme on preview?
actions = {
["default"] = actions.colorscheme,
["ctrl-y"] = function(selected) print(selected[2]) end,
["ctrl-y"] = function(selected) print(selected[1]) end,
},
winopts = {
win_height = 0.55,

@ -340,4 +340,14 @@ M.git_buf_vsplit = function(selected, opts)
M.git_buf_edit(selected, opts)
end
M.arg_add = function(selected, opts)
local vimcmd = "argadd"
M.vimcmd_file(vimcmd, selected, opts)
end
M.arg_del = function(selected, opts)
local vimcmd = "argdel"
M.vimcmd_file(vimcmd, selected, opts)
end
return M

@ -213,6 +213,15 @@ M.globals.grep = {
rg_opts = "--column --line-number --no-heading --color=always --smart-case",
actions = M.globals.files.actions,
}
M.globals.args = {
previewer = function() return M.globals.default_previewer end,
prompt = 'Args> ',
file_icons = true and M._has_devicons,
color_icons = true,
git_icons = true,
actions = M.globals.files.actions,
}
M.globals.args.actions["ctrl-x"] = actions.arg_del
M.globals.oldfiles = {
previewer = function() return M.globals.default_previewer end,
prompt = 'History> ',

@ -58,6 +58,7 @@ end
M.fzf_files = require'fzf-lua.core'.fzf_files
M.files = require'fzf-lua.providers.files'.files
M.files_resume = require'fzf-lua.providers.files'.files_resume
M.args = require'fzf-lua.providers.files'.args
M.grep = require'fzf-lua.providers.grep'.grep
M.live_grep = require'fzf-lua.providers.grep'.live_grep_native
M.live_grep_native = require'fzf-lua.providers.grep'.live_grep_native

@ -71,4 +71,43 @@ M.files_resume = function(opts)
return core.fzf_files(opts)
end
M.args = function(opts)
opts = config.normalize_opts(opts, config.globals.args)
if not opts then return end
local entries = vim.fn.execute("args")
entries = utils.strsplit(entries, "%s\n")
-- remove the current file indicator
-- remove all non-files
local args = {}
for _, s in ipairs(entries) do
if s:match('^%[') then
s = s:gsub('^%[', ''):gsub('%]$', '')
end
local st = vim.loop.fs_stat(s)
if opts.files_only == false or
st and st.type == 'file' then
table.insert(args, s)
end
end
entries = nil
opts.fzf_fn = function (cb)
for _, x in ipairs(args) do
x = core.make_entry_file(opts, x)
if x then
cb(x, function(err)
if err then return end
-- close the pipe to fzf, this
-- removes the loading indicator in fzf
cb(nil, function() end)
end)
end
end
utils.delayed_cb(cb)
end
return core.fzf_files(opts)
end
return M

@ -22,6 +22,14 @@ M._if = function(bool, a, b)
end
end
M.strsplit = function(inputstr, sep)
local t={}
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
table.insert(t, str)
end
return t
end
function M.round(num, limit)
if not num then return nil end
if not limit then limit = 0.5 end

Loading…
Cancel
Save