Skip to content

Commit

Permalink
feat: Add yazi file manager
Browse files Browse the repository at this point in the history
  • Loading branch information
Allaman committed May 17, 2024
1 parent 3d2ee71 commit f50612b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lua/core/plugins/alpha/alpha.lua
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ local buttons = {
{ type = "text", val = "Quick links", opts = { hl = "SpecialComment", position = "center" } },
dashboard.button("e", " New File", "<cmd>ene <BAR> startinsert<cr>"),
dashboard.button("f", " Find File", ":" .. require("utils.functions").project_files() .. "<cr>"),
dashboard.button("b", " File Browser", "<cmd>" .. require("utils.functions").file_browser() .. "<cr>"),
dashboard.button("b", " File Browser", require("utils.functions").file_browser()),
dashboard.button("s", " Search String", "<cmd>Telescope live_grep<cr>"),
dashboard.button("r", " Recent Files", "<cmd>Telescope oldfiles<cr>"),
dashboard.button("g", " NeoGit", "<cmd>Neogit<cr>"),
Expand Down
3 changes: 2 additions & 1 deletion lua/core/plugins/telescope.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ local telescopeConfig = require("telescope.config")
local telescope = require("telescope")
table.unpack = table.unpack or unpack -- 5.1 compatibility

---enable Telescope file_browser only if Lf is not set as file browser
---enable Telescope file_browser only if Lf or yazi is not set as file browser
local function enable_file_browser()
return not utils.safe_nested_config(plugins, "lf", "enable")
and not utils.safe_nested_config(plugins, "yazi", "enabled")
end

local function file_browser_config()
Expand Down
31 changes: 31 additions & 0 deletions lua/core/plugins/yazi.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
local user_config = vim.g.config.plugins.yazi or {}

local default_config = {
enabled = false,
keys = {
-- TODO: my mapping <leader>lf is soo good but in the LSP cluster
{
"<leader>lf",
function()
require("yazi").yazi(nil, vim.fn.getcwd())
end,
desc = "Open Yazi (file manager)",
},
},
opts = {
open_for_directories = true,
},
}

local config = vim.tbl_deep_extend("force", default_config, user_config)

return {
"mikavilpas/yazi.nvim",
enabled = config.enabled,
dependencies = {
"nvim-lua/plenary.nvim",
},
event = "VeryLazy",
keys = config.keys,
opts = config.opts,
}
7 changes: 5 additions & 2 deletions lua/utils/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,13 @@ end

-- Return file browser command
M.file_browser = function()
if vim.g.config.plugins.yazi.enabled then
return "<cmd>lua require('yazi').yazi(nil, vim.fn.getcwd())<cr>"
end
if vim.g.config.plugins.lf.enable then
return "Lf"
return "<cmd>Lf<cr>"
end
return "Telescope file_browser grouped=true"
return "<cmd>Telescope file_browser grouped=true<cr>"
end

-- toggle quickfixlist
Expand Down

0 comments on commit f50612b

Please sign in to comment.