tags keys and other improvements

This commit is contained in:
2026-03-16 09:39:08 +01:00
parent 8a0c8bc2d7
commit 28aca1a82b
7 changed files with 232 additions and 84 deletions

43
src/sh/keys.sh Normal file
View File

@@ -0,0 +1,43 @@
# This file defines the keys used in the keybindings
# The keys are comma separated. See `fzf --man` for the possible keys.
# List
KEYS_DOWN_HP="ctrl-d"
KEYS_UP_HP="ctrl-u"
KEYS_BACK="ctrl-h"
KEYS_ENTER="enter,ctrl-l"
KEYS_CANCEL="esc"
KEYS_ENTER_ALTERNATIVE="alt-enter"
KEYS_CYCLE_DISPLAY="ctrl-space"
KEYS_VIEW_SOURCE="alt-v"
KEYS_HTML_PREVIEW="alt-h"
KEYS_TAG_ADD="alt-+"
KEYS_TAG_REMOVE="alt--"
KEYS_ARCHIVE="ctrl-a"
KEYS_DELETE="ctrl-delete"
KEYS_FLAG_TOGGLE="ctrl-x"
KEYS_OPEN="ctrl-o"
KEYS_REPLY="ctrl-r"
KEYS_COMPOSE="ctrl-n"
# Preview window
KEYS_PREVIEW_DOWN="alt-j"
KEYS_PREVIEW_UP="alt-k"
KEYS_PREVIEW_DOWN_HP="page-up"
KEYS_PREVIEW_UP_HP="page-down"
KEYS_PREVIEW_TOGGLE_SIZE="alt-/"
# Keys specific to purge window
KEYS_PURGE_ALL="ctrl-alt-d"
# Change main views
KEYS_SEARCH_TAG_REPLCE="alt-t"
KEYS_SEARCH_TAG_APPEND="alt-T"
KEYS_SEARCH_FROM_REPLCE="alt-s"
KEYS_SEARCH_FROM_APPEND="alt-S"
KEYS_SEARCH_TO_REPLCE="alt-r"
KEYS_SEARCH_TO_APPEND="alt-R"
KEYS_SEARCH_EDIT_QUERY="alt-q"
KEYS_SEARCH_DELETED="alt-d"
KEYS_SEARCH_INBOX="alt-1"

View File

@@ -20,7 +20,7 @@ list_threads() {
# listed.
# @argument $1: query (optional)
list_tags() {
[ "${1:-}" ] && query="$1" || query="tag:/./"
[ "${1:-}" ] && query="$1" || query="*"
$NOTMUCH search --output=tags "$query"
}

View File

@@ -1,10 +1,16 @@
# Wrapper around notmuch
# notmuch new
# This is used for updating the notmuch database
nm_new() {
$NOTMUCH new
}
# Print the message id of the last message within a thread.
# @argument $1: thread id
nm_last_message_in_thread() {
# TODO: We may be smarter here that just incorporating excluded messages
$NOTMUCH search --output=messages --offset=-1 --exclude=false thread:"$1" | sed 's/^...//'
$NOTMUCH search --output=messages --offset=-1 thread:"$1" | sed 's/^...//'
}
# Print the header of a message (with trailing empty line)
@@ -39,3 +45,9 @@ nm_message_get_part() {
nm_tag() {
$NOTMUCH tag "$1" "$2"
}
# Get all files, also of excluded matches
# @argument $1: query
nm_files_all() {
$NOTMUCH search --output=files --exclude=false "$1"
}

View File

@@ -11,15 +11,10 @@
# @argument #3: if set, then the HTML messages will be taken
preview_message() {
[ "$1" = "id" ] && messageid="$2" || messageid="$(nm_last_message_in_thread "$2")"
echo "preview_message: messageid=$messageid" >> /tmp/foo
parts="$(nm_message_parts "$messageid")"
echo "preview_message: parts=$parts" >> /tmp/foo
html="${3:-}"
echo "preview_message: html=$html" >> /tmp/foo
nr="$(nm_message_part_nr "$messageid" "$html")"
echo "preview_message: nr=$nr" >> /tmp/foo
[ ! "$nr" ] && [ ! "$html" ] && html="html" && nr="$(nm_message_part_nr "$messageid" "html")"
echo "preview_message: nr=$nr" >> /tmp/foo
[ "$html" ] && parser="$PANDOC" || parser="cat"
nm_message_header "$messageid" | $CATEMAIL
[ "$nr" ] && (nm_message_get_part "$messageid" "$nr" | $parser | $CATMD)

13
src/sh/tags.sh Normal file
View File

@@ -0,0 +1,13 @@
# Default tags
# The deleted tag is by default the first tag defined in the exclude settings.
# If that does not exist, then it is "deleted".
TAG_DEL=${TAG_DEL:-$($NOTMUCH config get search.exclude_tags|head -1)}
TAG_DEL=${TAG_DEL:-deleted}
# Tag for messages in the inbox
TAG_INBOX=${TAG_INBOX:-inbox}
# White-space separates list of tags that are automatically added to new
# emails. These tags will be removed when the message/tread is archived.
TAGS_NEW=${TAGS_NEW:-$($NOTMUCH config get new.tags | xargs echo)}

24
src/sh/varia.sh Normal file
View File

@@ -0,0 +1,24 @@
# Various functions
# This prompts the user for a "yes" or a "no"
# @argument $1: Question
# @argument $2: Content to show in preview window
# @return: 0 if the user answered "yes" and 1 otherwise.
#!/bin/sh
ynprompt() {
return $(printf '0 \033[32myes\033[0m\n1 \033[31mno\033[0m\n' |
$FZF \
--sync \
--bind='start:pos(2)' \
--bind='ctrl-c,ctrl-g,ctrl-q,esc:pos(2)+accept' \
--reverse \
--no-input \
--header="$1" \
--preview-window='60%,border-line' \
--margin='5%,5%,5%,15%' \
--preview="echo \"$2\"" \
--with-nth=2 \
--accept-nth=1 \
--header-border='line' \
--color='border:yellow,header:yellow')
}