{ pkgs, config, ... }: let 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 # 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") 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 # 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 { programs.yazi = { enable = true; enableFishIntegration = true; settings = { manager = { show_hidden = true; sort_by = "natural"; sort_dir_first = true; linemode = "size"; }; }; }; home.packages = [ yazi-img-save ]; }