improvement: attachment feature

This commit is contained in:
Ämin Baumeler 2025-06-17 10:59:39 +02:00
parent c39c45a23a
commit 871a000cbd
3 changed files with 26 additions and 25 deletions

View File

@ -1,7 +1,8 @@
BEGIN { FS="[:;]" }
/^END:VEVENT$/ { ins = 0; exit }
/^[^ ]/ && a { a = 0 }
/^ / && a { print substr($0, 2) }
/^ / && a && p { print substr($0, 2); }
/^ / && a && !p { if (index($0, ":")) { p = 1; print substr($0, index($0, ":")+1) } }
/^ATTACH/ && ins { i++; }
/^ATTACH/ && ins && i == id { a = 1; print substr($0, index($0, ":")+1) }
/^ATTACH/ && ins && i == id { a = 1; if (index($0, ":")) { p = 1; print substr($0, index($0, ":")+1) } }
/^BEGIN:VEVENT$/ { ins = 1 }

View File

@ -14,7 +14,6 @@ function cont_reading(str) {
function att_info(i, str, cnt, k, info) {
str = substr(str, 1, index(str, ":") - 1)
cnt = split(str, props)
info = "Attachment "i":"
if (cnt > 1) {
for (k=2; k<=cnt; k++) {
pname = substr(props[k], 1, index(props[k], "=") - 1)
@ -28,12 +27,8 @@ function att_info(i, str, cnt, k, info) {
if (pname == "FMTTYPE")
type = pvalu
}
if (fin)
info = info " \"" fin "\""
if (type)
info = info " " type
if (enc)
info = info " (inline)"
info = "inline"
}
print i, fin, type, enc, info
}

View File

@ -1255,36 +1255,41 @@ while true; do
elif [ "$key" = "c" ] && [ -f "$ROOT/$fpath" ]; then
__tentative_toggle "$fpath"
elif [ "$key" = "a" ] && [ -f "$ROOT/$fpath" ]; then
echo "GO" >>/tmp/foo
att=$(
(
echo "1\t2\t3\t4\t5\t6"
awk "$AWK_ATTACHLS" "$ROOT/$fpath"
) |
awk "$AWK_ATTACHLS" "$ROOT/$fpath" |
$FZF \
--no-clear \
--delimiter="\t" \
--accept-nth=1,2,3,4 \
--with-nth=5 \
--with-nth="Attachment {1}: \"{2}\" {3} ({5})" \
--no-sort \
--tac \
--no-input \
--margin="30%,30%" \
--border=bold \
--border-label='Attachment View Keys: <enter> open, <ctrl-alt-d> delete, <shift-a> add' \
--expect="ctrl-c,esc,q,backspace,ctrl-alt-d,A" \
--border-label="Attachment View Keys: <enter> open, <ctrl-alt-d> delete, <shift-a> add" \
--expect="A" \
--expect="ctrl-c,ctrl-g,ctrl-q,ctrl-d,esc,q,backspace" \
--print-query \
--bind="start:hide-input" \
--bind="ctrl-alt-d:show-input+change-query(ctrl-alt-d)+accept" \
--bind="load:transform:[ \"\$FZF_TOTAL_COUNT\" -eq 0 ] && echo 'unbind(enter)+unbind(ctrl-alt-d)'" \
--bind="j:down" \
--bind="k:up"
--bind="k:up" ||
true
)
echo "GO" >>/tmp/foo
echo "$att" >>/tmp/foo
key=$(echo "$att" | head -1)
key=$(echo "$att" | head -2 | xargs)
sel=$(echo "$att" | tail -1)
if [ "$key" = "ctrl-c" ] || [ "$key" = "esc" ] || [ "$key" = "q" ] || [ "$key" = "backspace" ]; then
if [ "$key" = "ctrl-c" ] ||
[ "$key" = "ctrl-g" ] ||
[ "$key" = "ctrl-q" ] ||
[ "$key" = "ctrl-d" ] ||
[ "$key" = "esc" ] ||
[ "$key" = "q" ] ||
[ "$key" = "backspace" ]; then
continue
fi
if [ "$key" = "A" ]; then
__add_attachment "$fpath"
__refresh_data
continue
fi
attid=$(echo "$sel" | cut -f 1)
@ -1292,6 +1297,7 @@ while true; do
attfmt=$(echo "$sel" | cut -f 3)
attenc=$(echo "$sel" | cut -f 4)
if [ -z "$attid" ]; then
# This line should be unreachable
continue
fi
if [ "$key" = "ctrl-alt-d" ]; then
@ -1307,6 +1313,7 @@ while true; do
$GIT add "$fpath"
$GIT commit -m "Deleted attachment from event '$(__summary_for_commit "$fpath") ...'" -- "$fpath"
fi
__refresh_data
break
;;
"no")
@ -1352,8 +1359,6 @@ while true; do
;;
esac
done
printf "Press <enter> to conintue" >/dev/tty
read -r tmp
# Clean up
rm -f "$attpath"
if [ -n "${tmpdir:-}" ] && [ -d "${tmpdir:-}" ]; then