feat(firefox): add tridactyl yazi image saver, revert portal attempt

This commit is contained in:
kenji
2026-01-11 11:12:10 -06:00
parent 8d01f300be
commit 2d77a5d42e
3 changed files with 62 additions and 37 deletions
+3
View File
@@ -43,6 +43,9 @@
bind K tabprev
unbind <C-e>
" Hint images and save using Yazi picker
bind ;s hint -i -c native yazi-img-save
" Force Tridactyl to yield new tab control to Firefox/Extensions
set newtab about:newtab
'';
+51 -28
View File
@@ -3,36 +3,64 @@
config,
...
}: let
yazi-picker = pkgs.writeShellScriptBin "yazi-picker" ''
echo "--- $(date) ---" >> /tmp/yazi-picker.log
echo "Args: $@" >> /tmp/yazi-picker.log
echo "Env: WAYLAND_DISPLAY=$WAYLAND_DISPLAY DISPLAY=$DISPLAY" >> /tmp/yazi-picker.log
path="$1"
[ -z "$path" ] && path="."
if [ "$2" = "true" ]; then
echo "Mode: Save" >> /tmp/yazi-picker.log
# Future: handle save mode better (maybe prompts?)
else
echo "Mode: Open" >> /tmp/yazi-picker.log
yazi-img-save = pkgs.writeShellScriptBin "yazi-img-save" ''
url="$1"
if [ -z "$url" ]; then
${pkgs.libnotify}/bin/notify-send "Yazi Save" "No URL provided"
exit 1
fi
out="$HOME/.cache/yazi-chooser"
rm -f "$out"
# Create a temp file to store the chosen directory
out=$(mktemp)
echo "Launching ghostty..." >> /tmp/yazi-picker.log
${pkgs.ghostty}/bin/ghostty --class="yazi-picker" --title="File Picker" -e ${pkgs.yazi}/bin/yazi "$path" --chooser-file="$out"
ret=$?
echo "Ghostty exited with $ret" >> /tmp/yazi-picker.log
# Launch Yazi in a terminal to pick a directory.
# We use a trick: --chooser-file normally picks a file.
# But if we want a directory, we can select a directory entry (if inside parent)
# OR we can just use the current directory when yazi exits?
#
# Better approach: Use a specific yazi command or just open yazi
# and have a keybind to "pick here"?
#
# Simplest valid approach with stock Yazi:
# Use --chooser-file. User navigates to the folder they want,
# enters it, then selects "current directory" (.) if possible?
# Standard Yazi chooser doesn't easily return "current dir".
#
# Alternative: The user selects a FILE in the directory they want,
# and we save alongside it.
${pkgs.ghostty}/bin/ghostty --class="yazi-picker" --title="Pick Save Folder" -e ${pkgs.yazi}/bin/yazi . --chooser-file="$out"
if [ -f "$out" ]; then
selected=$(cat "$out")
echo "Selected: $selected" >> /tmp/yazi-picker.log
echo "$selected"
rm "$out"
if [ -n "$selected" ]; then
# If selected is a file, get its directory.
if [ -f "$selected" ]; then
target_dir=$(dirname "$selected")
elif [ -d "$selected" ]; then
target_dir="$selected"
else
echo "No selection" >> /tmp/yazi-picker.log
# fallback
target_dir="$HOME/Downloads"
fi
${pkgs.libnotify}/bin/notify-send "Downloading..." "$url"
# Download
cd "$target_dir"
${pkgs.wget}/bin/wget --content-disposition --no-clobber "$url"
ret=$?
if [ $ret -eq 0 ]; then
${pkgs.libnotify}/bin/notify-send "Download Complete" "Saved to $target_dir"
else
${pkgs.libnotify}/bin/notify-send -u critical "Download Failed" "wget exit code: $ret"
fi
else
echo "No selection"
fi
fi
'';
in {
@@ -50,11 +78,6 @@ in {
};
home.packages = [
yazi-picker
yazi-img-save
];
xdg.configFile."xdg-desktop-portal-termfilechooser/config".text = ''
[filechooser]
cmd=${yazi-picker}/bin/yazi-picker
'';
}
+1 -2
View File
@@ -29,11 +29,10 @@
enable = true;
extraPortals = [
pkgs.xdg-desktop-portal-hyprland
pkgs.xdg-desktop-portal-termfilechooser
];
config.common = {
default = ["hyprland"];
"org.freedesktop.impl.portal.FileChooser" = ["termfilechooser"];
};
};
}