-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from desdic/fzf
feat: Add support for fzf
- Loading branch information
Showing
7 changed files
with
166 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
local utils = require("greyjoy.utils") | ||
local greyjoy = require("greyjoy") | ||
|
||
local greycall = {} | ||
|
||
greycall.translate = function(obj) | ||
local orig_command = nil | ||
local commandinput = table.concat(obj.command, " ") | ||
if greyjoy.overrides[commandinput] then | ||
orig_command = obj.command | ||
obj.command = utils.str_to_array(greyjoy.overrides[commandinput]) | ||
obj.name = greyjoy.overrides[commandinput] | ||
end | ||
obj.orig_command = orig_command | ||
return obj | ||
end | ||
|
||
greycall.extensions = function(arg, callback, callbackoptions) | ||
local bufname = vim.api.nvim_buf_get_name(0) | ||
local filetype = vim.bo.filetype | ||
local pluginname = arg or "" | ||
local fileobj = utils.new_file_obj(greyjoy.patterns, bufname, filetype) | ||
local rootdir = fileobj.rootdir | ||
for plugin, obj in pairs(greyjoy.extensions) do | ||
local plugin_obj = obj | ||
local plugin_type = plugin_obj.type | ||
|
||
if | ||
pluginname == "" | ||
or pluginname == plugin | ||
or greyjoy.__in_group(pluginname, plugin) | ||
then | ||
local output = {} | ||
if plugin_type == "global" then | ||
output = plugin_obj.parse(fileobj) | ||
callback(output, callbackoptions) | ||
else | ||
if rootdir then | ||
for _, file in pairs(plugin_obj.files) do | ||
if utils.file_exists(rootdir .. "/" .. file) then | ||
local fileinfo = { | ||
filename = file, | ||
filepath = rootdir, | ||
} | ||
output = plugin_obj.parse(fileinfo) | ||
callback(output, callbackoptions) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
return greycall |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
local greyfzf = {} | ||
|
||
local utils = require("greyjoy.utils") | ||
local greyjoy = require("greyjoy") | ||
local callback = require("greyjoy.callback") | ||
|
||
local fzfcallback = function(output, callbackoptions) | ||
for _, result in ipairs(output) do | ||
local translated = callback.translate(result) | ||
table.insert(callbackoptions.content, translated) | ||
callbackoptions.count = callbackoptions.count + 1 | ||
|
||
local key = callbackoptions.count .. ":" .. translated.name | ||
callbackoptions.content[key] = translated | ||
|
||
vim.schedule(function() | ||
callbackoptions.fzf_cb(key, function() | ||
coroutine.resume(callbackoptions.co) | ||
end) | ||
end) | ||
coroutine.yield() | ||
end | ||
end | ||
|
||
greyfzf.run = function(arg) | ||
local fzf = require("fzf-lua") | ||
local content = {} | ||
local count = 0 | ||
|
||
fzf.fzf_exec(function(fzf_cb) | ||
coroutine.wrap(function() | ||
local co = coroutine.running() | ||
|
||
callback.extensions(arg, fzfcallback, { | ||
co = co, | ||
fzf_cb = fzf_cb, | ||
content = content, | ||
count = count, | ||
}) | ||
|
||
fzf_cb() | ||
end)() | ||
end, { | ||
prompt = "Run> ", | ||
actions = { | ||
[greyjoy.ui.fzf.keys.select] = { | ||
fn = function(selected) | ||
local cmd = content[selected[1]] | ||
greyjoy.execute(cmd) | ||
end, | ||
silent = true, | ||
}, | ||
[greyjoy.ui.fzf.keys.edit] = { | ||
fn = function(selected) | ||
local command = content[selected[1]] | ||
|
||
local commandinput = table.concat(command.command, " ") | ||
|
||
vim.ui.input( | ||
{ prompt = "Edit", default = commandinput }, | ||
function(input) | ||
if input then | ||
if command.orig_command then | ||
local tmp = | ||
table.concat(command.orig_command, " ") | ||
greyjoy.overrides[tmp] = input | ||
else | ||
greyjoy.overrides[commandinput] = input | ||
end | ||
|
||
command.command = utils.str_to_array(input) | ||
greyjoy.execute(command) | ||
end | ||
end | ||
) | ||
end, | ||
silent = true, | ||
}, | ||
}, | ||
}) | ||
end | ||
|
||
return greyfzf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters