#!/bin/bash
# Pick file using yazi for neomutt attachment

tmpfile=/tmp/neomutt-yazi-pick

if [ -z "$1" ]; then
    cd ~
    yazi --chooser-file="$tmpfile" &&
        awk 'BEGIN {printf "%s", "push "} {printf "%s", "<attach-file>\"" $0 "\"<enter>"}' "$tmpfile" >"${tmpfile}.cmd" &&
        mv "${tmpfile}.cmd" "$tmpfile"
elif [ "$1" == "clean" ]; then
    rm -f "$tmpfile"
fi
