fix xdg-deskop-portal-termfilechooser yazi-wrapper

This commit is contained in:
Lennart J. Kurzweg (Nx2)
2025-07-29 16:07:35 +02:00
parent 42a4a2fe0e
commit f22ef9939c

View File

@@ -50,8 +50,8 @@
{ on = "<C-f>"; run = "arrow 100%"; desc = "Move cursor down one page"; }
{ on = "<PageUp>"; run = "arrow -100%"; desc = "Move cursor up one page"; }
{ on = "<PageDown>"; 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" "<Space>" ]; 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";