From c62dd7b8a45529285138854977163f7cebde3b13 Mon Sep 17 00:00:00 2001 From: Matt Nish-Lapidus Date: Mon, 21 Apr 2025 12:39:28 -0400 Subject: [PATCH] working on yazi as file picker --- flake.lock | 12 +++---- hosts/eddie/configuration.nix | 1 + modules/home/desktop.nix | 6 ++-- modules/home/file-chooser/config | 6 ++++ modules/home/file-chooser/yazi-wrapper.sh | 40 +++++++++++++++++++++++ modules/home/yazi.nix | 2 ++ 6 files changed, 58 insertions(+), 9 deletions(-) create mode 100644 modules/home/file-chooser/config create mode 100755 modules/home/file-chooser/yazi-wrapper.sh diff --git a/flake.lock b/flake.lock index 0f1b0c1..3be7770 100644 --- a/flake.lock +++ b/flake.lock @@ -362,11 +362,11 @@ ] }, "locked": { - "lastModified": 1745205007, - "narHash": "sha256-k67bEcLkSo13TIBfs0CGYkJjG12aaikabMtxWbSeqr0=", + "lastModified": 1745251259, + "narHash": "sha256-Hf8WEJMMoP6Fe+k+PYkVJFk5UKory2S0jW7HqRVqQFc=", "owner": "nix-community", "repo": "home-manager", - "rev": "3fbe9a2b76ff5c4dcb2a2a2027dac31cfc993c8c", + "rev": "82ee14ff60611b46588ea852f267aafcc117c8c8", "type": "github" }, "original": { @@ -1534,11 +1534,11 @@ "rust-overlay": "rust-overlay_3" }, "locked": { - "lastModified": 1745240671, - "narHash": "sha256-6r2Qmk7XsZtfPEod9Jh07Wp85bkm10yZi+LqO+GMGR8=", + "lastModified": 1745246655, + "narHash": "sha256-gB4anxOio0bAJi/GVePLwm8kx7WccFTNiON4y0ASin0=", "owner": "sxyazi", "repo": "yazi", - "rev": "7169e19ff01458b25dc6d0a0489bcac3b6c02904", + "rev": "5e283402ceb2ddea03200020b60a10a099c09896", "type": "github" }, "original": { diff --git a/hosts/eddie/configuration.nix b/hosts/eddie/configuration.nix index 59337a7..4542687 100644 --- a/hosts/eddie/configuration.nix +++ b/hosts/eddie/configuration.nix @@ -154,6 +154,7 @@ win-spice xwayland-satellite openrazer-daemon + xdg-desktop-portal-termfilechooser ]; # Bootloader. diff --git a/modules/home/desktop.nix b/modules/home/desktop.nix index 319a3b1..951c8a0 100644 --- a/modules/home/desktop.nix +++ b/modules/home/desktop.nix @@ -28,11 +28,9 @@ rpi-imager freecad flatpak - gst_all_1.gstreamer prusa-slicer via vial - scribus pdfarranger tdf pdfchain @@ -44,6 +42,9 @@ soundconverter wmctrl + scribus + gimp3 + # godot_4 # gdtoolkit_4 @@ -96,7 +97,6 @@ krita-plugin-gmic rawtherapee inkscape - gimp # kicad turbocase openscad-unstable diff --git a/modules/home/file-chooser/config b/modules/home/file-chooser/config new file mode 100644 index 0000000..7398943 --- /dev/null +++ b/modules/home/file-chooser/config @@ -0,0 +1,6 @@ +### $XDG_CONFIG_HOME/xdg-desktop-portal-termfilechooser/config ### + +[filechooser] +cmd=yazi-wrapper.sh +default_dir=$HOME +env=TERMCMD= wezlauncher diff --git a/modules/home/file-chooser/yazi-wrapper.sh b/modules/home/file-chooser/yazi-wrapper.sh new file mode 100755 index 0000000..457d218 --- /dev/null +++ b/modules/home/file-chooser/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:-wezlauncher ''}" + +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" diff --git a/modules/home/yazi.nix b/modules/home/yazi.nix index b2ff9a8..8a0eba2 100644 --- a/modules/home/yazi.nix +++ b/modules/home/yazi.nix @@ -198,4 +198,6 @@ xdg.configFile."yazi/theme.toml".source = ./yazi/theme.toml; xdg.configFile."yazi/flavors".source = ./yazi/flavors; + xdg.configFile."xdg-desktop-portal-termfilechooser/config".source = ./file-chooser/config; + home.file.".local/bin/yazi-wrapper.sh".source = ./file-chooser/yazi-wrapper.sh; }