Update xplr config

This commit is contained in:
James Dugan 2025-04-26 14:35:51 -06:00
parent c047fe2d55
commit 25439ab68d
3 changed files with 55 additions and 2 deletions

48
.config/xplr/fzf.lua Executable file
View file

@ -0,0 +1,48 @@
-- Basic fzf search integration for xplr
-- Requires fzf (obviously), and bat for the preview
---@diagnostic disable
local xplr = xplr
---@diagnostic enable
local fzf = function()
-- xplr.util.shell_execute doesn't work here since fzf needs an actual tty
local p = io.popen("fzf --preview='bat --color=always {}'", "r")
local output = p:read("*a")
p:close()
local lines = {}
for line in output:gmatch("[^\r\n]+") do
table.insert(lines, line)
end
local count = #lines
if count == 0 then
return
else
local path = lines[1]
local msgs = { { FocusPath = path } }
local isdir = xplr.util.shell_execute("test", { "-d", path }).returncode == 0
if isdir then
table.insert(msgs, "Enter")
else
table.insert(msgs, "PrintFocusPathAndQuit")
end
return msgs
end
end
xplr.fn.custom.fzf = {}
xplr.fn.custom.fzf.search = function(_)
return fzf()
end
xplr.config.modes.builtin.default.key_bindings.on_key["f"] = {
help = "fzf search",
messages = {
"PopMode",
{ CallLua = "custom.fzf.search" }
}
}

View file

@ -1,4 +1,4 @@
version = "0.21.9" -- This needs to be global; ignore diagnostics that say otherwise version = "1.0.0" -- This needs to be global; ignore diagnostics that say otherwise
---@diagnostic disable ---@diagnostic disable
local xplr = xplr local xplr = xplr
@ -52,3 +52,6 @@ xplr.config.modes.builtin.default.key_bindings.on_key['*'] = {
}, },
}, },
} }
-- Fzf
require("fzf")

View file

@ -19,7 +19,7 @@ local function filetype(n)
local type = "other" local type = "other"
if n.is_file then if n.is_file then
local mime = mimetype(n) local mime = mimetype(n)
if (mime:match("text") or mime:match("json") or mime:match("csv") or mime:match("empty")) then if (mime:match("text") or mime:match("json") or mime:match("csv") or mime:match("empty") or mime:match("javascript")) then
type = "text" type = "text"
elseif (mime:match("zip") or mime:match("tar")) then elseif (mime:match("zip") or mime:match("tar")) then
type = "archive" type = "archive"
@ -49,6 +49,8 @@ local function render_text(n, ctx)
end end
local function render_image(n, ctx) local function render_image(n, ctx)
-- xplr doesn't support image protocols such as sixel or kitty
-- so we need to render blocks instead
local result = xplr.util.shell_execute("viu", local result = xplr.util.shell_execute("viu",
{ "--blocks", "--static", "--width", ctx.layout_size.width, n.absolute_path }) { "--blocks", "--static", "--width", ctx.layout_size.width, n.absolute_path })
return (result.returncode == 0 and result.stdout) or stats(n) return (result.returncode == 0 and result.stdout) or stats(n)