From 63becaaa09a1e383cc452fccb037359850b1d1ab Mon Sep 17 00:00:00 2001 From: kenji Date: Sun, 11 Jan 2026 10:44:25 -0600 Subject: [PATCH] feat(hyprland): integrate yazi as global file picker via xdg-portal --- apps/hyprland/hypr/rules.nix | 8 +++++++ apps/yazi/default.nix | 42 +++++++++++++++++++++++++++++++++++- modules/nixos/hyprland.nix | 12 +++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/apps/hyprland/hypr/rules.nix b/apps/hyprland/hypr/rules.nix index b02cc05..26e070a 100644 --- a/apps/hyprland/hypr/rules.nix +++ b/apps/hyprland/hypr/rules.nix @@ -4,6 +4,14 @@ ]; windowrulev2 = [ + "suppressevent maximize, class:.*" + + # --- YAZI FILE PICKER --- + "float, class:^(yazi-picker)$" + "center, class:^(yazi-picker)$" + "size 60% 60%, class:^(yazi-picker)$" + "dimaround, class:^(yazi-picker)$" + ]; }; } diff --git a/apps/yazi/default.nix b/apps/yazi/default.nix index 5d8dd48..c76f49a 100644 --- a/apps/yazi/default.nix +++ b/apps/yazi/default.nix @@ -1,4 +1,35 @@ -{pkgs, ...}: { +{ + pkgs, + config, + ... +}: let + yazi-picker = pkgs.writeShellScriptBin "yazi-picker" '' + path="$1" + [ -z "$path" ] && path="." + + if [ "$2" = "true" ]; then + # Save file mode + # In save mode, we might want to just open the directory, + # but yazi --chooser-file works for picking a file to overwrite or a directory. + # For a "Save As" flow where you type a name, standard yazi chooser might be limited + # without custom lua, but selecting a directory works. + # For now, treat same as open. + : + fi + + out="$HOME/.cache/yazi-chooser" + rm -f "$out" + + # We need to block until ghostty closes, or use --wait if available/default behavior. + # Ghostty -e does not automatically detach, so it should block. + ${pkgs.ghostty}/bin/ghostty --class="yazi-picker" --title="File Picker" -e ${pkgs.yazi}/bin/yazi "$path" --chooser-file="$out" + + if [ -f "$out" ]; then + cat "$out" + rm "$out" + fi + ''; +in { programs.yazi = { enable = true; enableFishIntegration = true; @@ -11,4 +42,13 @@ }; }; }; + + home.packages = [ + yazi-picker + ]; + + xdg.configFile."xdg-desktop-portal-termfilechooser/config".text = '' + [filechooser] + cmd=${yazi-picker}/bin/yazi-picker + ''; } diff --git a/modules/nixos/hyprland.nix b/modules/nixos/hyprland.nix index f19a764..612658e 100644 --- a/modules/nixos/hyprland.nix +++ b/modules/nixos/hyprland.nix @@ -24,4 +24,16 @@ default = ["${myConfig.terminal.default}"]; }; }; + + xdg.portal = { + enable = true; + extraPortals = [ + pkgs.xdg-desktop-portal-hyprland + pkgs.xdg-desktop-portal-termfilechooser + ]; + config.common = { + default = ["hyprland"]; + "org.freedesktop.impl.portal.FileChooser" = "termfilechooser"; + }; + }; } \ No newline at end of file