diff --git a/.config/xplr/fzf.lua b/.config/xplr/fzf.lua new file mode 100755 index 0000000..c74e6d4 --- /dev/null +++ b/.config/xplr/fzf.lua @@ -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" } + } +} diff --git a/.config/xplr/init.lua b/.config/xplr/init.lua index adcbcc8..3dc6de4 100644 --- a/.config/xplr/init.lua +++ b/.config/xplr/init.lua @@ -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 local xplr = xplr @@ -52,3 +52,6 @@ xplr.config.modes.builtin.default.key_bindings.on_key['*'] = { }, }, } + +-- Fzf +require("fzf") diff --git a/.config/xplr/preview.lua b/.config/xplr/preview.lua index a19b34b..9a147be 100644 --- a/.config/xplr/preview.lua +++ b/.config/xplr/preview.lua @@ -19,7 +19,7 @@ local function filetype(n) local type = "other" if n.is_file then 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" elseif (mime:match("zip") or mime:match("tar")) then type = "archive" @@ -49,6 +49,8 @@ local function render_text(n, ctx) end 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", { "--blocks", "--static", "--width", ctx.layout_size.width, n.absolute_path }) return (result.returncode == 0 and result.stdout) or stats(n)