Skip to content

Commit

Permalink
feat: add fzf-lua support and fzf extra theme
Browse files Browse the repository at this point in the history
  • Loading branch information
mehalter committed Jul 15, 2024
1 parent a5468ae commit c94f756
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ term.foreground
| [bufferline.nvim](https://github.com/akinsho/bufferline.nvim) | `bufferline` |
| [dashboard-nvim](https://github.com/glepnir/dashboard-nvim) | `dashboard-nvim` |
| [flash.nvim](https://github.com/folke/flash.nvim) | `flash` |
| [fzf-lua](https://github.com/ibhagwan/fzf-lua) | `fzf` |
| [gitsigns.nvim](https://github.com/lewis6991/gitsigns.nvim) | `gitsigns` |
| [hop.nvim](https://github.com/phaazon/hop.nvim) | `hop` |
| [indent_blankline.nvim](https://github.com/lukas-reineke/indent-blankline.nvim) | `indent-blankline` |
Expand Down
76 changes: 76 additions & 0 deletions lua/astrotheme/extras/fzf.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
local M = {}

--- @param highlights table<string, vim.api.keyset.highlight>
function M.generate(_, highlights)
local links = {
FzfLuaFzfCursorLine = "CursorLine",
FzfLuaFzfMatch = "Special",
FzfLuaFzfBorder = "FzfLuaBorder",
FzfLuaFzfScrollbar = "FzfLuaBorder",
FzfLuaFzfSeparator = "FzfLuaBorder",
FzfLuaFzfGutter = "FzfLuaNormal",
FzfLuaFzfHeader = "FzfLuaTitle",
FzfLuaFzfInfo = "NonText",
FzfLuaFzfPointer = "Special",
FzfLuaFzfMarker = "FzfLuaFzfPointer",
FzfLuaFzfSpinner = "FzfLuaFzfPointer",
FzfLuaFzfPrompt = "Special",
FzfLuaFzfQuery = "FzfLuaNormal",
FzfLuaNormal = "Normal",
}

local spec = {
["fg"] = { "fg", "FzfLuaNormal" },
["bg"] = { "bg", "FzfLuaNormal" },
["hl"] = { "fg", "FzfLuaFzfMatch" },
["fg+"] = { "fg", "FzfLuaFzfCursorLine" },
["bg+"] = { "bg", "FzfLuaFzfCursorLine" },
["hl+"] = { "fg", "FzfLuaFzfMatch" },
["info"] = { "fg", "FzfLuaFzfInfo" },
["border"] = { "fg", "FzfLuaFzfBorder" },
["separator"] = { "fg", "FzfLuaFzfSeparator" },
["scrollbar"] = { "fg", "FzfLuaFzfScrollbar" },
["gutter"] = { "bg", "FzfLuaFzfGutter" },
["query"] = { "fg", "FzfLuaFzfQuery", "regular" },
["prompt"] = { "fg", "FzfLuaFzfPrompt" },
["pointer"] = { "fg", "FzfLuaFzfPointer" },
["marker"] = { "fg", "FzfLuaFzfMarker" },
["spinner"] = { "fg", "FzfLuaFzfSpinner" },
["header"] = { "fg", "FzfLuaFzfHeader" },
}
local ret = {}

for c, v in pairs(spec) do
local hl_group = v[2]
while hl_group and not highlights[hl_group] do
hl_group = links[hl_group]
end
assert(hl_group, "hl_group not found for " .. v[2])
local hl = highlights[hl_group]
while hl and (type(hl) == "string" or hl.link) do
hl = highlights[type(hl) == "string" and hl or hl.link]
end
assert(hl, "hl not found for " .. hl_group)
local color = hl[v[1]]
assert(color, "color not found for " .. c .. ":" .. hl_group)
if type(color) == "number" then color = string.format("#%06x", color) end
if color:lower() ~= "none" then
local line = string.format("--color=%s:%s", c, color)
if v[3] then line = line .. ":" .. v[3] end
ret[#ret + 1] = " " .. line .. " \\"
end
end
table.sort(ret)
return ([[
export FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS \
--highlight-line \
--info=inline-right \
--ansi \
--layout=reverse \
--border=none \
%s
"
]]):format(table.concat(ret, "\n"))
end

return M
1 change: 1 addition & 0 deletions lua/astrotheme/extras/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ M.extras = {
fish = { ext = "fish", url = "https://fishshell.com/docs/current/index.html", label = "Fish" },
fish_themes = { ext = "theme", url = "https://fishshell.com/docs/current/interactive.html#syntax-highlighting", label = "Fish Themes" },
foot = { ext = "ini", url = "https://codeberg.org/dnkl/foot", label = "Foot" },
fzf = { ext = "sh", url = "https://github.com/junegunn/fzf", label = "Fzf" },
ghostty = { ext = "config", url = "https://github.com/ghostty-org", label = "Ghostty" },
gitui = { ext = "ron", url = "https://github.com/extrawurst/gitui", label = "GitUI" },
helix = { ext = "toml", url = "https://helix-editor.com/", label = "Helix" },
Expand Down
22 changes: 22 additions & 0 deletions lua/astrotheme/groups/plugins/fzf.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---@type AstroThemeCallback
local function callback(c, opts)
local bg = (opts.border and opts.inactive and c.ui.base) or (opts.float and c.ui.prompt) or c.ui.prompt
return {
FzfLuaBorder = {
fg = (opts.border and c.ui.border) or (opts.inactive and c.ui.base) or (opts.float and c.ui.prompt) or c.ui.base,
bg = bg,
},
FzfLuaTitle = {
fg = (opts.title_invert and c.ui.float) or c.ui.title,
bg = (opts.title_invert and c.ui.title)
or (opts.inactive and c.ui.base)
or (opts.transparent and opts.float and c.ui.base)
or (opts.float and c.ui.float)
or (opts.transparent and c.none)
or c.ui.base,
bold = true,
},
}
end

return callback
1 change: 1 addition & 0 deletions lua/astrotheme/groups/plugins/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ return {
["bufferline.nvim"] = "bufferline",
["dashboard-nvim"] = "dashboard-nvim",
["flash.nvim"] = "flash",
["fzf-lua"] = "fzf",
["gitsigns.nvim"] = "gitsigns",
["hop.nvim"] = "hop",
["indent-blankline.nvim"] = "indent-blankline",
Expand Down

0 comments on commit c94f756

Please sign in to comment.