From 4b2d5e6049cc903fba1ac7249dd295a410bd556c Mon Sep 17 00:00:00 2001 From: Daniel Fichtinger Date: Fri, 4 Apr 2025 15:40:18 -0400 Subject: [PATCH] AutoYADM commit: 2025-04-04 15:40:18 --- .config/xdg-desktop-portal/yazi-wrapper.sh | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 .config/xdg-desktop-portal/yazi-wrapper.sh diff --git a/.config/xdg-desktop-portal/yazi-wrapper.sh b/.config/xdg-desktop-portal/yazi-wrapper.sh new file mode 100755 index 00000000..53e4c7e0 --- /dev/null +++ b/.config/xdg-desktop-portal/yazi-wrapper.sh @@ -0,0 +1,40 @@ +#!/bin/sh +# This wrapper script is invoked by xdg-desktop-portal-termfilechooser. +# +# For more information about input/output arguments read `xdg-desktop-portal-termfilechooser(5)` + +set -ex +PATH="/usr/bin:/bin" + +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 's/"/\\"/g') + # escape spaces + command="$command \"$escaped\"" +done + +sh -c "$command"