122 lines
3.7 KiB
Nix
122 lines
3.7 KiB
Nix
{ pkgs, ... }:
|
|
let
|
|
hx-zellij-open = pkgs.writeShellScriptBin "hx-zellij-open" ''
|
|
set -eu
|
|
if [ -z "''${ZELLIJ:-}" ]; then
|
|
exec "''${EDITOR:-hx}" "$@"
|
|
fi
|
|
zellij="${pkgs.zellij}/bin/zellij"
|
|
"$zellij" action move-focus right
|
|
"$zellij" action write 27
|
|
for f in "$@"; do
|
|
"$zellij" action write-chars ":open \"$f\""
|
|
"$zellij" action write 13
|
|
done
|
|
'';
|
|
|
|
helixOpener = [
|
|
{ run = ''hx-zellij-open "$@"''; desc = "Open in Helix pane"; block = false; for = "unix"; }
|
|
];
|
|
|
|
tomlFormat = pkgs.formats.toml { };
|
|
|
|
ideYaziToml = tomlFormat.generate "yazi.toml" {
|
|
mgr = {
|
|
ratio = [ 0 1 0 ];
|
|
linemode = "none";
|
|
};
|
|
opener.edit = helixOpener;
|
|
};
|
|
|
|
ideKeymapToml = tomlFormat.generate "keymap.toml" {
|
|
mgr.prepend_keymap = [
|
|
{ on = "h"; run = "plugin bounded-leave"; desc = "Parent dir (stop at project root)"; }
|
|
{ on = "<Left>"; run = "plugin bounded-leave"; desc = "Parent dir (stop at project root)"; }
|
|
];
|
|
};
|
|
|
|
boundedLeave = ''
|
|
--- @sync entry
|
|
local function entry()
|
|
local cwd = tostring(cx.active.current.cwd)
|
|
local root = os.getenv("YAZI_ROOT")
|
|
if root and root ~= "" and cwd == root then
|
|
-- At the project root: refuse to go higher.
|
|
return
|
|
end
|
|
ya.emit("leave", {})
|
|
end
|
|
|
|
return { entry = entry }
|
|
'';
|
|
|
|
yazi-ide = pkgs.writeShellScriptBin "yazi-ide" ''
|
|
set -eu
|
|
export YAZI_CONFIG_HOME="$HOME/.config/yazi-ide"
|
|
root="$(${pkgs.git}/bin/git rev-parse --show-toplevel 2>/dev/null || true)"
|
|
export YAZI_ROOT="''${root:-$PWD}"
|
|
exec ${pkgs.yazi}/bin/yazi "$@"
|
|
'';
|
|
|
|
ideThemeToml = tomlFormat.generate "theme.toml" {
|
|
status = {
|
|
overall = { fg = "#abb2bf"; bg = "#21252b"; }; # readable text on a dark bar
|
|
progress_label = { fg = "#abb2bf"; bold = true; };
|
|
progress_normal = { fg = "#98c379"; bg = "#21252b"; };
|
|
progress_error = { fg = "#e06c75"; bg = "#21252b"; };
|
|
};
|
|
mode = {
|
|
normal_main = { fg = "#21252b"; bg = "#61afef"; bold = true; };
|
|
normal_alt = { fg = "#61afef"; bg = "#21252b"; };
|
|
select_main = { fg = "#21252b"; bg = "#98c379"; bold = true; };
|
|
select_alt = { fg = "#98c379"; bg = "#21252b"; };
|
|
unset_main = { fg = "#21252b"; bg = "#e06c75"; bold = true; };
|
|
unset_alt = { fg = "#e06c75"; bg = "#21252b"; };
|
|
};
|
|
};
|
|
in
|
|
{
|
|
home.packages = [ hx-zellij-open yazi-ide ];
|
|
|
|
programs.yazi = {
|
|
enable = true;
|
|
enableZshIntegration = true;
|
|
shellWrapperName = "y";
|
|
settings.opener.edit = helixOpener;
|
|
};
|
|
|
|
|
|
xdg.configFile = {
|
|
"yazi-ide/yazi.toml".source = ideYaziToml;
|
|
"yazi-ide/theme.toml".source = ideThemeToml;
|
|
"yazi-ide/keymap.toml".source = ideKeymapToml;
|
|
"yazi-ide/plugins/bounded-leave.yazi/main.lua".text = boundedLeave;
|
|
|
|
"yazi-ide/init.lua".text = ''
|
|
-- Render the header path relative to YAZI_ROOT (the project root you
|
|
-- launched the layout in), anchored on the project's directory name.
|
|
-- Outside that root, fall back to Yazi's default ~/-style path.
|
|
function Header:cwd()
|
|
local max = self._area.w - self._right_width
|
|
if max <= 0 then
|
|
return ""
|
|
end
|
|
|
|
local cwd = tostring(self._current.cwd)
|
|
local root = os.getenv("YAZI_ROOT") or ""
|
|
local s
|
|
if root ~= "" and (cwd == root or cwd:sub(1, #root + 1) == root .. "/") then
|
|
local base = root:match("([^/]+)/?$") or root -- project dir name
|
|
s = base .. cwd:sub(#root + 1) -- e.g. "myrepo/src/lib"
|
|
else
|
|
s = ya.readable_path(cwd)
|
|
end
|
|
|
|
s = s .. self:flags()
|
|
return ui.Span(ui.truncate(s, { max = max, rtl = true })):style(th.mgr.cwd)
|
|
end
|
|
'';
|
|
};
|
|
}
|
|
|