feat: open attachments with ctrl-o

This commit is contained in:
2026-03-12 15:32:37 +01:00
parent eb8f4574bf
commit 1453fdb3ad

View File

@@ -64,11 +64,58 @@ if [ "${1:-}" = "--view-source" ]; then
exit
fi
if [ "${1:-}" = "--show-message-parts" ]; then
shift
messageid="$1"
nm_message_parts "$messageid"
exit
fi
# FZF default configs
FZF_DEFAULT_PREVIEW_WINDOW="right,80,border-line,wrap-word"
FZF_ALTERNATE_PREVIEW_WINDOW="bottom,80%,border-line,wrap-word"
FZF_DEFAULT_THREAD_LINE="{1} {3} ({4})"
if [ "${1:-}" = "--open-part" ]; then
shift
messageid="$1"
res=$(nm_message_parts "$messageid" | awk '{print NR"\t"$0}' | $FZF \
--raw \
--reverse \
--wrap=word \
--delimiter="$(printf '\t')" \
--with-nth=2 \
--accept-nth=1 \
--margin='30%' \
--bind='ctrl-d:half-page-down,ctrl-u:half-page-up' \
--bind='page-up:preview-half-page-up,page-down:preview-half-page-down' \
--bind="ctrl-h,backward-eof:abort" || true)
[ "$res" ] || exit
tmpfile=$(mktemp)
nm_message_get_part "$messageid" "$res" > "$tmpfile"
file "$tmpfile"
while true; do
printf "Are you sure you want to open \"%s\"? (yes/no): " "$tmpfile" >/dev/tty
read -r yn
case $yn in
"yes")
open "$tmpfile" >/dev/null 2>/dev/stdout
printf "Press <enter> to continue." >/dev/tty
read -r tmp
break
;;
"no")
break
;;
*)
echo "Please answer \"yes\" or \"no\"." >/dev/tty
;;
esac
done
rm -f "$tmpfile"
exit
fi
if [ "${1:-}" = "--show-thread" ]; then
shift
thread="$1"
@@ -88,7 +135,8 @@ if [ "${1:-}" = "--show-thread" ]; then
--bind="alt-/:change-preview-window($FZF_ALTERNATE_PREVIEW_WINDOW|$FZF_DEFAULT_PREVIEW_WINDOW)" \
--bind="alt-v:execute:$0 --view-source {5}" \
--bind="alt-h:change-preview:$0 --preview-html-message {5}" \
--bind="focus:change-preview:$0 --preview-message {5}" \
--bind="focus:change-preview($0 --preview-message {5})+transform-footer:printf '\033[4mMesssage parts\033[0m\n';$0 --show-message-parts {5}" \
--bind="ctrl-o:execute:$0 --open-part {5}" \
--preview="$0 --preview-message {5}" \
--preview-window="$FZF_DEFAULT_PREVIEW_WINDOW" || true)
exit