From f22ef9939c4b409ca06351217ee1d99dbb00bac6 Mon Sep 17 00:00:00 2001 From: "Lennart J. Kurzweg (Nx2)" Date: Tue, 29 Jul 2025 16:07:35 +0200 Subject: [PATCH] fix xdg-deskop-portal-termfilechooser yazi-wrapper --- home-modules/yazi.nix | 71 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 60 insertions(+), 11 deletions(-) diff --git a/home-modules/yazi.nix b/home-modules/yazi.nix index 5afc36f..74af1fa 100644 --- a/home-modules/yazi.nix +++ b/home-modules/yazi.nix @@ -50,8 +50,8 @@ { on = ""; run = "arrow 100%"; desc = "Move cursor down one page"; } { on = ""; run = "arrow -100%"; desc = "Move cursor up one page"; } { on = ""; run = "arrow 100%"; desc = "Move cursor down one page"; } - { on = [ "g" "g" ]; run = "arrow down"; desc = "Move cursor to the top"; } - { on = [ "g" "e" ]; run = "arrow up"; desc = "Move cursor to the end"; } + { on = [ "g" "g" ]; run = "arrow top"; desc = "Move cursor to the top"; } + { on = [ "g" "e" ]; run = "arrow bot"; desc = "Move cursor to the end"; } { on = [ "g" "h" ]; run = "cd ~"; desc = "Go to the home directory"; } { on = [ "g" "n" ]; run = "cd ~/nix-dots"; desc = "Go to the Nix-Dotfiles directory"; } (pkgs.lib.mkIf (hyper.host == "NxACE") { on = [ "g" "s" ]; run = "cd /var/lib/hugo/nx2site"; desc = "Go to the Hugo Nx2.Site directory"; }) @@ -65,6 +65,7 @@ { on = [ "g" "d" ]; run = "cd ~/Downloads"; desc = "Go to the downloads directory"; } { on = [ "g" "D" ]; run = "cd ~/Documents"; desc = "Go to the Documents directory"; } { on = [ "g" "r" ]; run = "cd /"; desc = "Go to the root (/) directory"; } + { on = [ "g" "p" ]; run = "cd ~/projects"; desc = "Go to the projects directory"; } { on = [ "g" "/" ]; run = "cd /"; desc = "Go to the root (/) directory"; } { on = [ "g" "" ]; run = "cd --interactive"; desc = "Go to a directory interactively"; } # Navigation @@ -396,17 +397,65 @@ }; }; xdg = { - configFile."xdg-desktop-portal-termfilechooser/config".text = lib.mkIf config.programs.yazi.enable '' - [filechooser] - cmd=${pkgs.xdg-desktop-portal-termfilechooser}/share/xdg-desktop-portal-termfilechooser/yazi-wrapper.sh - env=TERMCMD=ghostty --title="terminal-file-picker -e" - default_dir=$HOME - open_mode=suggested - save_mode=last - ''; + # # https://github.com/hunkyburrito/xdg-desktop-portal-termfilechooser/pull/44 + configFile = let + wrapper = pkgs.writeShellApplication { name = "yazi-wrapper.sh"; text = /*bash*/ '' + set -ex + + multiple="$1" + directory="$2" + save="$3" + path="$4" + out="$5" + + cmd="yazi" + termcmd="''${TERMCMD:-kitty --title 'termfilechooser'}" + + if [ "$save" = "1" ]; then + # save a file + set -- --chooser-file="$out" "$path" + elif [ "$directory" = "1" ]; then + # upload files from a directory + set -- --chooser-file="$out" --cwd-file="$out" "$path" + elif [ "$multiple" = "1" ]; then + # upload multiple files + set -- --chooser-file="$out" "$path" + else + # upload only 1 file + set -- --chooser-file="$out" "$path" + fi + + command="$termcmd $cmd" + for arg in "$@"; do + # escape double quotes + escaped=$(printf "%s" "$arg" | sed -E 's/[\"\(\)\{\}\|]//g') + # escape spaces + command="$command \"$escaped\"" + done + + sh -c "$command" + '';}; + in { + "xdg-desktop-portal-termfilechooser/config".text = '' + [filechooser] + cmd=${wrapper}/bin/yazi-wrapper.sh + env=TERMCMD=ghostty --title="terminal-file-picker -e" + default_dir=$HOME + open_mode=suggested + save_mode=last + ''; + # "xdg-desktop-portal-termfilechooser/config".text = '' + # [filechooser] + # cmd=${pkgs.latest.xdg-desktop-portal-termfilechooser}/share/xdg-desktop-portal-termfilechooser/yazi-wrapper.sh + # env=TERMCMD=ghostty --title="terminal-file-picker -e" + # default_dir=$HOME + # open_mode=suggested + # save_mode=last + # ''; + }; portal = { enable = true; - extraPortals = [ pkgs.xdg-desktop-portal-termfilechooser ]; + extraPortals = [ pkgs.latest.xdg-desktop-portal-termfilechooser ]; config = { common = { "org.freedesktop.impl.portal.FileChooser" = "termfilechooser";