diff --git a/apps/firefox/default.nix b/apps/firefox/default.nix index e3b12ee..c5bc057 100644 --- a/apps/firefox/default.nix +++ b/apps/firefox/default.nix @@ -43,6 +43,9 @@ bind K tabprev unbind + " 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 ''; diff --git a/apps/yazi/default.nix b/apps/yazi/default.nix index 9f8cc45..0559a4e 100644 --- a/apps/yazi/default.nix +++ b/apps/yazi/default.nix @@ -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" - - 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 + # Create a temp file to store the chosen directory + out=$(mktemp) + # 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" - else - echo "No selection" >> /tmp/yazi-picker.log + + 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 + # 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 - ''; } diff --git a/modules/nixos/hyprland.nix b/modules/nixos/hyprland.nix index 40fbb2e..4fd0578 100644 --- a/modules/nixos/hyprland.nix +++ b/modules/nixos/hyprland.nix @@ -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"]; - }; - }; -} \ No newline at end of file + config.common = { + default = ["hyprland"]; + }; + }; + } + \ No newline at end of file