yazi: open from other apps

This commit is contained in:
2026-05-31 14:54:06 +03:00
parent 7ea803d7cd
commit 5b2fbe0db4
+237 -121
View File
@@ -1,134 +1,250 @@
{ pkgs, lib, inputs, ... }: { { pkgs, lib, inputs, ... }: let
home.packages = with pkgs; [ hostSystem = pkgs.stdenv.hostPlatform.system;
( ouch.override { enableUnfree = true; } )
];
wayland.windowManager.hyprland.settings.windowrule = [ yaziPkg = inputs.yazi.packages.${hostSystem}.default.override {
"match:class dragon-drop, move cursor_x-window_w/2 cursor_y-window_h/2" _7zz = pkgs._7zz-rar;
]; };
programs.yazi = { yaziOpen = pkgs.writeShellScriptBin "yazi-open" ''
package = inputs.yazi.packages set -efu
.${pkgs.stdenv.hostPlatform.system}.default
.override { _7zz = pkgs._7zz-rar; };
enable = true;
enableZshIntegration = true;
shellWrapperName = "y";
settings = { target="''${1:-$HOME}"
mgr = {
show_hidden = true;
};
preview = {
max_width = 1000;
max_height = 1000;
};
plugin = {
preloaders = [
{ url = "*.crdownload"; run = "noop"; }
];
prepend_previewers = [ case "$target" in
{ mime = "application/xz"; run = "ouch"; } file://*)
{ mime = "application/zip"; run = "ouch"; } target="$(${lib.getExe pkgs.python3} -c 'import sys, urllib.parse; print(urllib.parse.unquote(urllib.parse.urlparse(sys.argv[1]).path))' "$target")"
{ mime = "application/rar"; run = "ouch"; } ;;
{ mime = "application/gzip"; run = "ouch"; } esac
{ mime = "application/7z-compressed"; run = "ouch"; }
];
prepend_fetchers = [ if [ -f "$target" ]; then
{ group = "git"; url = "*"; run = "git"; } target="$(dirname "$target")"
]; fi
};
};
plugins = let if [ ! -e "$target" ]; then
yaziPlugin = name: pkgs.stdenvNoCC.mkDerivation { target="$HOME"
pname = "${name}.yazi"; fi
version = "unstable";
src = inputs.yazi-plugins;
installPhase = '' exec ${lib.getExe pkgs.ghostty} --title="Yazi" -e ${lib.getExe yaziPkg} "$target"
runHook preInstall '';
mkdir -p $out
cp -r ${name}.yazi/* $out/
rm -f $out/LICENSE
cp LICENSE $out/LICENSE
runHook postInstall
'';
};
in with pkgs.yaziPlugins; {
inherit
chmod
ouch
mount
toggle-pane
;
full-border = {
package = yaziPlugin "full-border";
setup = true;
};
starship = { fileManager1 = pkgs.writeShellScriptBin "yazi-filemanager1" ''
package = starship; exec ${pkgs.python3.withPackages (ps: [ ps.dbus-next ])}/bin/python ${pkgs.writeText "yazi-filemanager1.py" ''
setup = true; import asyncio
}; import os
import subprocess
import urllib.parse
git = { from dbus_next.aio import MessageBus
package = git; from dbus_next.constants import BusType
setup = true; from dbus_next.service import ServiceInterface, method
};
};
initLua = '' YAZI_OPEN = ${builtins.toJSON (lib.getExe yaziOpen)}
Status:children_add(function()
local h = cx.active.current.hovered
if not h or ya.target_family() ~= "unix" then
return ""
end
return ui.Line {
ui.Span(ya.user_name(h.cha.uid) or tostring(h.cha.uid)):fg("magenta"),
":",
ui.Span(ya.group_name(h.cha.gid) or tostring(h.cha.gid)):fg("magenta"),
" ",
}
end, 500, Status.RIGHT)
'';
keymap = { def uri_to_path(uri: str) -> str | None:
mgr.prepend_keymap = [ parsed = urllib.parse.urlparse(uri)
{ if parsed.scheme != "file":
on = "T"; return None
run = "plugin toggle-pane max-preview"; return urllib.parse.unquote(parsed.path)
desc = "Maximize or restore the preview pane";
}
{ def open_paths(uris: list[str], reveal_items: bool = False) -> None:
on = "Y"; for uri in uris:
run = ''shell -- for path in %s; do echo "file://$path"; done | wl-copy -t text/uri-list''; path = uri_to_path(uri)
desc = "Copy files into system clipboard"; if not path:
} continue
{
on = ["c" "m"]; if reveal_items and os.path.isfile(path):
run = "plugin chmod"; path = os.path.dirname(path)
desc = "Chmod on selected files";
} subprocess.Popen(
{ [YAZI_OPEN, path],
on = ["M"]; start_new_session=True,
run = "plugin mount"; stdout=subprocess.DEVNULL,
desc = "Open mount menu"; stderr=subprocess.DEVNULL,
} )
{
on = [ "<C-n>" ];
run = "shell '${lib.getExe pkgs.dragon-drop} -x -A -i -T %s'"; class FileManager1(ServiceInterface):
} def __init__(self) -> None:
{ super().__init__("org.freedesktop.FileManager1")
on = [ "g" "<S-d>" ];
run = ''cd /mnt/D''; @method()
desc = "Goto D drive"; def ShowFolders(self, uris: "as", startup_id: "s") -> "":
} open_paths(uris)
];
}; @method()
}; def ShowItems(self, uris: "as", startup_id: "s") -> "":
open_paths(uris, reveal_items=True)
@method()
def ShowItemProperties(self, uris: "as", startup_id: "s") -> "":
open_paths(uris, reveal_items=True)
async def main() -> None:
bus = await MessageBus(bus_type=BusType.SESSION).connect()
bus.export("/org/freedesktop/FileManager1", FileManager1())
await bus.request_name("org.freedesktop.FileManager1")
await asyncio.Event().wait()
asyncio.run(main())
''}
'';
in {
home.packages = with pkgs; [
( ouch.override { enableUnfree = true; } )
yaziOpen
];
xdg.desktopEntries.yazi = {
name = "Yazi";
genericName = "File Manager";
exec = "${lib.getExe yaziOpen} %U";
terminal = false;
mimeType = [ "inode/directory" ];
categories = [ "System" "FileTools" "FileManager" ];
startupNotify = false;
};
xdg.mimeApps = {
enable = true;
defaultApplications = {
"inode/directory" = "yazi.desktop";
"application/x-gnome-saved-search" = "yazi.desktop";
};
};
xdg.dataFile."dbus-1/services/org.freedesktop.FileManager1.service".text = ''
[D-BUS Service]
Name=org.freedesktop.FileManager1
Exec=${lib.getExe fileManager1}
'';
wayland.windowManager.hyprland.settings.windowrule = [
"match:class dragon-drop, move cursor_x-window_w/2 cursor_y-window_h/2"
];
programs.yazi = {
package = yaziPkg;
enable = true;
enableZshIntegration = true;
shellWrapperName = "y";
settings = {
mgr = {
show_hidden = true;
};
preview = {
max_width = 1000;
max_height = 1000;
};
plugin = {
preloaders = [
{ url = "*.crdownload"; run = "noop"; }
];
prepend_previewers = [
{ mime = "application/xz"; run = "ouch"; }
{ mime = "application/zip"; run = "ouch"; }
{ mime = "application/rar"; run = "ouch"; }
{ mime = "application/gzip"; run = "ouch"; }
{ mime = "application/7z-compressed"; run = "ouch"; }
];
prepend_fetchers = [
{ group = "git"; url = "*"; run = "git"; }
];
};
};
plugins = let
yaziPlugin = name: pkgs.stdenvNoCC.mkDerivation {
pname = "${name}.yazi";
version = "unstable";
src = inputs.yazi-plugins;
installPhase = ''
runHook preInstall
mkdir -p $out
cp -r ${name}.yazi/* $out/
rm -f $out/LICENSE
cp LICENSE $out/LICENSE
runHook postInstall
'';
};
in with pkgs.yaziPlugins; {
inherit
chmod
ouch
mount
toggle-pane
;
full-border = {
package = yaziPlugin "full-border";
setup = true;
};
starship = {
package = starship;
setup = true;
};
git = {
package = git;
setup = true;
};
};
initLua = ''
Status:children_add(function()
local h = cx.active.current.hovered
if not h or ya.target_family() ~= "unix" then
return ""
end
return ui.Line {
ui.Span(ya.user_name(h.cha.uid) or tostring(h.cha.uid)):fg("magenta"),
":",
ui.Span(ya.group_name(h.cha.gid) or tostring(h.cha.gid)):fg("magenta"),
" ",
}
end, 500, Status.RIGHT)
'';
keymap = {
mgr.prepend_keymap = [
{
on = "T";
run = "plugin toggle-pane max-preview";
desc = "Maximize or restore the preview pane";
}
{
on = "Y";
run = ''shell -- for path in %s; do echo "file://$path"; done | wl-copy -t text/uri-list'';
desc = "Copy files into system clipboard";
}
{
on = ["c" "m"];
run = "plugin chmod";
desc = "Chmod on selected files";
}
{
on = ["M"];
run = "plugin mount";
desc = "Open mount menu";
}
{
on = [ "<C-n>" ];
run = "shell '${lib.getExe pkgs.dragon-drop} -x -A -i -T %s'";
}
{
on = [ "g" "<S-d>" ];
run = ''cd /mnt/D'';
desc = "Goto D drive";
}
];
};
};
} }