lsv.config({
config_version = 1,
icons = {
enabled = true, preset = nil, font = "Nerd", default_file = "", default_dir = "", mappings = require("nerdfont-icons"), },
keys = {
sequence_timeout_ms = 600, },
ui = {
panes = { parent = 30, current = 40, preview = 30 },
show_hidden = false, max_list_items = 5000, date_format = "%Y-%m-%d %H:%M",
header = {
left = "{username|fg=cyan;style=bold}@{hostname|fg=cyan}:{cwd|fg=#ffd866}/{current_file_name|fg=#ffd866;style=bold}",
right = "{current_file_size|fg=gray} {owner|fg=gray} {current_file_permissions|fg=gray} {current_file_ctime|fg=gray}",
fg = "gray", bg = "#181825", },
header_fg = nil, header_bg = nil,
row = {
icon = " ", left = "{name}", middle = "", right = "{info}", },
row_widths = { icon = 2, left = 40, middle = 0, right = 14 },
display_mode = "friendly",
sort = nil, sort_reverse = false, show = nil,
confirm_delete = true,
theme = require("themes/catppuccin"),
modals = {
prompt = { width_pct = 50, height_pct = 40 }, confirm = { width_pct = 50, height_pct = 40 }, theme = { width_pct = 60, height_pct = 60 }, },
},
})
local function shquote(s)
return lsv.quote(tostring(s))
end
local OS = lsv.get_os_name()
lsv.set_previewer(function(ctx)
if ctx.current_file_extension == "md" or ctx.current_file_extension == "markdown" then
if OS == "windows" then
return string.format(
"glow --style=dark --line-numbers=true --width %d %s",
ctx.preview_width - 2,
shquote(ctx.current_file)
)
else
return string.format(
"head -n %d %s | glow --style=dark --line-numbers=true --width %d",
ctx.preview_height,
shquote(ctx.current_file),
ctx.preview_width - 2
)
end
elseif
ctx.current_file_extension == "jpg"
or ctx.current_file_extension == "jpeg"
or ctx.current_file_extension == "png"
or ctx.current_file_extension == "gif"
or ctx.current_file_extension == "bmp"
or ctx.current_file_extension == "tiff"
then
return string.format(
"VIU_NO_KITTY=1 viu --static --width %d --height %d %s",
ctx.preview_width - 2,
ctx.preview_height - 4,
shquote(ctx.current_file)
)
elseif not ctx.is_binary then
return string.format(
"bat --color=always --style=numbers --paging=never --wrap=never --line-range=:%d %s",
ctx.preview_height,
shquote(ctx.current_file)
)
else
local bytes = math.max(256, (ctx.preview_height - 4 or 20) * 16)
return string.format("hexyl -n %d %s", bytes, shquote(ctx.current_file))
end
end)
lsv.map_action("ss", "Sort by size + show size", function(lsv, config)
config.ui.sort = "size"
config.ui.show = "size"
end)
lsv.map_action("t", "New tmux window here", function(lsv, config)
local dir = (config.context and config.context.cwd) or "."
lsv.os_run_interactive(string.format("tmux new-window -c %s", lsv.quote(dir)))
end)
lsv.map_action("gs", "Git Status", function(lsv, config)
local dir = (config.context and config.context.cwd) or "."
lsv.os_run(string.format("git -C %s status", lsv.quote(dir)))
end)
lsv.map_action("E", "Edit in $EDITOR (preview)", function(lsv, config)
local path = (config.context and config.context.current_file) or "."
local cmd = string.format("%s %s", "$EDITOR", lsv.quote(path))
if OS == "windows" then
cmd = string.format("bat --paging=always %s", lsv.quote(path))
end
lsv.os_run_interactive(cmd)
end)
lsv.map_action("e", "Edit in nvim", function(lsv, config)
local path = (config.context and config.context.current_file) or "."
lsv.os_run_interactive(string.format("$EDITOR %s", shquote(path)))
end)
lsv.map_action("i", "View file", function(lsv, config)
local path = (config.context and config.context.current_file) or "."
lsv.os_run_interactive(string.format("bat --paging=always %s", shquote(path)))
end)
lsv.map_action("fd", "Diff selected files", function(lsv, config)
local paths = lsv.get_selected_paths()
local n = #paths
if n < 2 then
lsv.show_error("Diff: select 2 files")
return
end
if n > 2 then
lsv.show_message(string.format("Diff: using first 2 of %d", n))
end
local a = shquote(paths[1])
local b = shquote(paths[2])
local user_tool = lsv.getenv("DIFF_TOOL")
local cmd
if user_tool and #user_tool > 0 then
cmd = string.format("%s %s %s", user_tool, a, b)
elseif OS == "windows" then
cmd = string.format("git --no-pager diff --no-index --color=always %s %s", a, b)
else
cmd = string.format("git --no-pager diff --no-index --color=always %s %s", a, b)
end
lsv.os_run_interactive(cmd)
end)
lsv.map_action("<C-m>", "Clear messages", function(lsv, config)
lsv.clear_messages()
end)