feat(util): simple function to get an icon

This commit is contained in:
Folke Lemaitre 2024-12-01 09:06:52 +01:00
parent d517b11cab
commit 7c29848e89
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
3 changed files with 35 additions and 12 deletions

View file

@ -156,14 +156,17 @@ See the example below for how to configure `snacks.nvim`.
}
},
keys = {
{ "<leader>un", function() Snacks.notifier.hide() end, desc = "Dismiss All Notifications" },
{ "<leader>.", function() Snacks.scratch() end, desc = "Toggle Scratch Buffer" },
{ "<leader>S", function() Snacks.scratch.select() end, desc = "Select Scratch Buffer" },
{ "<leader>n", function() Snacks.notifier.show_history() end, desc = "Notification History" },
{ "<leader>bd", function() Snacks.bufdelete() end, desc = "Delete Buffer" },
{ "<leader>gg", function() Snacks.lazygit() end, desc = "Lazygit" },
{ "<leader>gb", function() Snacks.git.blame_line() end, desc = "Git Blame Line" },
{ "<leader>gB", function() Snacks.gitbrowse() end, desc = "Git Browse" },
{ "<leader>gf", function() Snacks.lazygit.log_file() end, desc = "Lazygit Current File History" },
{ "<leader>gl", function() Snacks.lazygit.log() end, desc = "Lazygit Log (cwd)" },
{ "<leader>cR", function() Snacks.rename.rename_file() end, desc = "Rename File" },
{ "<leader>gB", function() Snacks.gitbrowse() end, desc = "Git Browse" },
{ "<leader>gb", function() Snacks.git.blame_line() end, desc = "Git Blame Line" },
{ "<leader>gf", function() Snacks.lazygit.log_file() end, desc = "Lazygit Current File History" },
{ "<leader>gg", function() Snacks.lazygit() end, desc = "Lazygit" },
{ "<leader>gl", function() Snacks.lazygit.log() end, desc = "Lazygit Log (cwd)" },
{ "<leader>un", function() Snacks.notifier.hide() end, desc = "Dismiss All Notifications" },
{ "<c-/>", function() Snacks.terminal() end, desc = "Toggle Terminal" },
{ "<c-_>", function() Snacks.terminal() end, desc = "which_key_ignore" },
{ "]]", function() Snacks.words.jump(vim.v.count1) end, desc = "Next Reference", mode = { "n", "t" } },

View file

@ -21,14 +21,17 @@ return {
}
},
keys = {
{ "<leader>un", function() Snacks.notifier.hide() end, desc = "Dismiss All Notifications" },
{ "<leader>.", function() Snacks.scratch() end, desc = "Toggle Scratch Buffer" },
{ "<leader>S", function() Snacks.scratch.select() end, desc = "Select Scratch Buffer" },
{ "<leader>n", function() Snacks.notifier.show_history() end, desc = "Notification History" },
{ "<leader>bd", function() Snacks.bufdelete() end, desc = "Delete Buffer" },
{ "<leader>gg", function() Snacks.lazygit() end, desc = "Lazygit" },
{ "<leader>gb", function() Snacks.git.blame_line() end, desc = "Git Blame Line" },
{ "<leader>gB", function() Snacks.gitbrowse() end, desc = "Git Browse" },
{ "<leader>gf", function() Snacks.lazygit.log_file() end, desc = "Lazygit Current File History" },
{ "<leader>gl", function() Snacks.lazygit.log() end, desc = "Lazygit Log (cwd)" },
{ "<leader>cR", function() Snacks.rename.rename_file() end, desc = "Rename File" },
{ "<leader>gB", function() Snacks.gitbrowse() end, desc = "Git Browse" },
{ "<leader>gb", function() Snacks.git.blame_line() end, desc = "Git Blame Line" },
{ "<leader>gf", function() Snacks.lazygit.log_file() end, desc = "Lazygit Current File History" },
{ "<leader>gg", function() Snacks.lazygit() end, desc = "Lazygit" },
{ "<leader>gl", function() Snacks.lazygit.log() end, desc = "Lazygit Log (cwd)" },
{ "<leader>un", function() Snacks.notifier.hide() end, desc = "Dismiss All Notifications" },
{ "<c-/>", function() Snacks.terminal() end, desc = "Toggle Terminal" },
{ "<c-_>", function() Snacks.terminal() end, desc = "which_key_ignore" },
{ "]]", function() Snacks.words.jump(vim.v.count1) end, desc = "Next Reference", mode = { "n", "t" } },

View file

@ -52,4 +52,21 @@ function M.bo(buf, bo)
end
end
---@param name string
---@param cat? string
---@return string, string?
function M.icon(name, cat)
-- stylua: ignore
local try = {
function() return require("mini.icons").get(cat or "file", name) end,
function() return require("nvim-web-devicons").get_icon(name) end,
}
for _, fn in ipairs(try) do
local ret = { pcall(fn) }
if ret[1] then
return ret[2], ret[3]
end
end
return ""
end
return M