term file choose works again

This commit is contained in:
Lennart J. Kurzweg (Nx2)
2025-08-27 22:21:58 +02:00
parent efe96374de
commit 01deb843e4
2 changed files with 81 additions and 129 deletions

View File

@@ -1,7 +1,9 @@
{ pkgs, ... }@all: with all;
{
home.packages = with pkgs; [
unar
{ pkgs, ... }@all: with all; let
tfc = pkgs.latest.xdg-desktop-portal-termfilechooser;
in {
home.packages = [
pkgs.unar
tfc
];
programs.yazi = {
@@ -403,73 +405,23 @@
};
};
xdg = {
# # 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 = ''
configFile."xdg-desktop-portal-termfilechooser/config" = {
force = true;
text = ''
[filechooser]
cmd=${wrapper}/bin/yazi-wrapper.sh
cmd=${tfc}/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
'';
# "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.latest.xdg-desktop-portal-termfilechooser ];
config = {
common = {
"org.freedesktop.impl.portal.FileChooser" = "termfilechooser";
};
};
xdgOpenUsePortal = true;
config.common."org.freedesktop.impl.portal.FileChooser" = "termfilechooser";
extraPortals = [ tfc ];
};
};
home.sessionVariables = {
GTK_USE_PORTAL = "1";
};
home.sessionVariables."GTK_USE_PORTAL" = "1";
}