{ pkgs, myConfig, ... }: let # Yazi wrapper for xdg-desktop-portal-termfilechooser # TODO: rewrite in the future 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; settings = { manager = { show_hidden = true; sort_by = "natural"; sort_dir_first = true; linemode = "size"; }; tasks = { image_bound = [10000 10000]; }; }; }; # 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)$" ]; }