diff --git a/apps/yazi/default.nix b/apps/yazi/default.nix index ab10323..c4b3600 100644 --- a/apps/yazi/default.nix +++ b/apps/yazi/default.nix @@ -2,7 +2,74 @@ pkgs, myConfig, ... -}: { +}: let + # Yazi wrapper for xdg-desktop-portal-termfilechooser + yaziWrapper = pkgs.writeShellScript "yazi-wrapper.sh" '' + if [[ "$6" == "1" ]]; then + set -x + fi + + multiple="$1" + directory="$2" + save="$3" + path="$4" + out="$5" + + termcmd="${pkgs.util-linux}/bin/setsid uwsm-app -- xdg-terminal-exec --app-id=org.hakase.popup.yazi -e" + + cleanup() { + if [ -f "$tmpfile" ]; then + rm "$tmpfile" || : + fi + if [ "$save" = "1" ] && [ ! -s "$out" ]; then + rm "$path" || : + fi + } + + trap cleanup EXIT HUP INT QUIT ABRT TERM + + if [ "$save" = "1" ]; then + tmpfile=$(mktemp) + + printf '%s' 'xdg-desktop-portal-termfilechooser saving files tutorial + + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !!! === WARNING! === !!! + !!! The contents of *whatever* file you open last in !!! + !!! yazi will be *overwritten*! !!! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + + Instructions: + 1) Move this file wherever you want. + 2) Rename the file if needed. + 3) Confirm your selection by opening the file, for + example by pressing . + + Notes: + 1) This file is provided for your convenience. You can + only choose this placeholder file otherwise the save operation aborted. + 2) If you quit yazi without opening a file, this file + will be removed and the save operation aborted. + ' >"$path" + + $termcmd ${pkgs.yazi}/bin/yazi --chooser-file="$tmpfile" "$path" + elif [ "$directory" = "1" ]; then + $termcmd ${pkgs.yazi}/bin/yazi --cwd-file="$out" "$path" + elif [ "$multiple" = "1" ]; then + $termcmd ${pkgs.yazi}/bin/yazi --chooser-file="$out" "$path" + else + $termcmd ${pkgs.yazi}/bin/yazi --chooser-file="$out" "$path" + fi + + # Handle save file case + if [ "$save" = "1" ] && [ -s "$tmpfile" ]; then + selected_file=$(head -n 1 "$tmpfile") + if [ -f "$selected_file" ] && grep -qi "^xdg-desktop-portal-termfilechooser saving files tutorial" "$selected_file"; then + echo "$selected_file" >"$out" + fi + fi + ''; +in { programs.yazi = { enable = true; enableFishIntegration = true; @@ -15,4 +82,31 @@ }; }; }; + + # Portal packages need to be in user profile for proper path resolution + home.packages = [ + pkgs.xdg-desktop-portal-hyprland + pkgs.xdg-desktop-portal-gtk + pkgs.xdg-desktop-portal-termfilechooser + ]; + + # xdg-desktop-portal-termfilechooser configuration + xdg.configFile."xdg-desktop-portal-termfilechooser/config".text = '' + [filechooser] + cmd=${yaziWrapper} + default_dir=$HOME/Downloads + ''; + + # Portal routing configuration - use termfilechooser for file dialogs + xdg.configFile."xdg-desktop-portal/portals.conf".text = '' + [preferred] + default=hyprland;gtk + org.freedesktop.impl.portal.FileChooser=termfilechooser + ''; + wayland.windowManager.hyprland.settings.windowrulev2 = [ + # File picker yazi - floating, centered, smaller size + "float, class:^(org\\.hakase\\.popup\\.yazi)$" + "size 60% 70%, class:^(org\\.hakase\\.popup\\.yazi)$" + "center, class:^(org\\.hakase\\.popup\\.yazi)$" + ]; } diff --git a/modules/nixos/hyprland.nix b/modules/nixos/hyprland.nix index f19a764..097fa9e 100644 --- a/modules/nixos/hyprland.nix +++ b/modules/nixos/hyprland.nix @@ -24,4 +24,12 @@ default = ["${myConfig.terminal.default}"]; }; }; + + # XDG Desktop Portal - portal packages are in home-manager for proper path resolution + xdg.portal.enable = true; + + # Required for portal file chooser integration + environment.sessionVariables = { + GTK_USE_PORTAL = "1"; + }; } \ No newline at end of file