Skip to content

Commit

Permalink
fix: previewer for plugins
Browse files Browse the repository at this point in the history
refactor: chdir
  • Loading branch information
phanen committed Mar 29, 2024
1 parent 2a80a11 commit 8858e30
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
32 changes: 25 additions & 7 deletions lua/fzf-lua-overlay/providers/plugins.lua
Original file line number Diff line number Diff line change
@@ -1,27 +1,45 @@
local cfg = require 'fzf-lua-overlay.config'
local lazy_cfg = package.loaded['lazy.core.config']

local previewer = require('fzf-lua.previewer.fzf')

local lazy_previewer = previewer.cmd_async:extend()

function lazy_previewer:new(o, op, fzf_win)
lazy_previewer.super.new(self, o, op, fzf_win)
self.cmd = 'ls'
setmetatable(self, lazy_previewer)
return self
end

function lazy_previewer:cmdline(o)
o = o or {}
self.cwd = lazy_cfg.options.root
local act = require('fzf-lua.shell').raw_preview_action_cmd(function(items, _)
local name = items[1]
return ('%s %s'):format('ls --color', lazy_cfg.plugins[name].dir)
end, '{}', self.opts.debug)
return act
end

return {
'fzf_exec',
{
prompt = 'plugins> ',
preview = ('ls --color %s/{1}'):format(cfg.plugins_dir),
previewer = lazy_previewer,
actions = {
['default'] = function(selected)
if not selected or not selected[1] then
return
end
local name = selected[1]
local plugin = package.loaded['lazy.core.config'].plugins[name]
local path = plugin.dir
vim.system { 'zoxide', 'add', path }
vim.api.nvim_set_current_dir(path)
require('util').chdir(lazy_cfg.plugins[name].dir)
end,
},
},
function(fzf_cb)
coroutine.wrap(function()
local co = coroutine.running()
local plugins = package.loaded['lazy.core.config'].plugins
local plugins = lazy_cfg.plugins
for plugin in pairs(plugins) do
fzf_cb(plugin, function()
coroutine.resume(co)
Expand Down
3 changes: 1 addition & 2 deletions lua/fzf-lua-overlay/providers/zoxide.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ return {
return
end
local path = selected[1]:match '/.+'
vim.system { 'zoxide', 'add', path }
vim.api.nvim_set_current_dir(path)
require('util').chdir(path)
end,
},
},
Expand Down
7 changes: 7 additions & 0 deletions lua/fzf-lua-overlay/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,11 @@ util.getregion = function(mode)
return getregion(mode)
end

util.chdir = function(path)
if vim.fn.executable('zoxide') then
vim.system { 'zoxide', 'add', path }
end
vim.api.nvim_set_current_dir(path)
end

return util

0 comments on commit 8858e30

Please sign in to comment.