feat: html rendering
This commit is contained in:
68
src/main.sh
68
src/main.sh
@@ -17,47 +17,43 @@ set -eu
|
||||
# tools
|
||||
. "sh/tools.sh"
|
||||
|
||||
# history
|
||||
# query history
|
||||
. "sh/history.sh"
|
||||
|
||||
__notmuch_search() {
|
||||
$NOTMUCH search "$*" \
|
||||
| sed "s/^thread:\([[:xdigit:]]\+\)\s\+\([^[]\+\)\s\+\[\([^]]\+\)\]\([^;]*\); \(.*\) (\([^(]*\))$/${COLDATE}\2${COLRESET}\t${COLCNTS}\3${COLRESET}\t${COLFROM}\4${COLRESET}\t${COLSUBJ}\5${COLRESET}\t${COLTAGS}\6${COLRESET}\t\1/" \
|
||||
| column -s "$(printf '\t')" -t -l 3 -R 1,2
|
||||
}
|
||||
# notmuch functions
|
||||
. "sh/notmuch.sh"
|
||||
|
||||
__notmuch_thread() {
|
||||
$NOTMUCH show thread:"$1" \
|
||||
| awk "$AWK_THREADOVERVIEW" \
|
||||
| sed "s/^\(\S*\)\t\([^\t]*\)\t\(.*\) (\([^()]*\)) (\([^()]*\))$/${COLFROM}\3${COLRESET}\t${COLSUBJ}\2${COLRESET}\t${COLDATE}\4${COLRESET}\t${COLTAGS}\5${COLRESET}\t\1/"
|
||||
}
|
||||
|
||||
__notmuch_list_tags() {
|
||||
$NOTMUCH search --output=tags tag:/./
|
||||
}
|
||||
|
||||
__notmuch_list_address() {
|
||||
$NOTMUCH address '*'
|
||||
}
|
||||
# list generators
|
||||
. "sh/lists.sh"
|
||||
|
||||
# preview functions
|
||||
. "sh/preview.sh"
|
||||
|
||||
if [ "${1:-}" = "--preview-thread" ]; then
|
||||
shift
|
||||
thread="$1"
|
||||
$NOTMUCH show thread:$thread \
|
||||
| awk "$AWK_LASTMESSAGEINTHREAD" \
|
||||
| tail -n +2 \
|
||||
| $CAT
|
||||
threadid="$1"
|
||||
preview_message "thread" "$threadid"
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ "${1:-}" = "--preview-html-thread" ]; then
|
||||
shift
|
||||
threadid="$1"
|
||||
preview_message "thread" "$threadid" "html"
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ "${1:-}" = "--preview-message" ]; then
|
||||
shift
|
||||
messageid="$1"
|
||||
$NOTMUCH show id:$messageid \
|
||||
| awk "$AWK_LASTMESSAGEINTHREAD" \
|
||||
| tail -n +2 \
|
||||
| $CAT
|
||||
preview_message "id" "$messageid"
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ "${1:-}" = "--preview-html-message" ]; then
|
||||
shift
|
||||
messageid="$1"
|
||||
preview_message "id" "$messageid" "html"
|
||||
exit
|
||||
fi
|
||||
|
||||
@@ -76,7 +72,7 @@ FZF_DEFAULT_THREAD_LINE="{1} {3} ({4})"
|
||||
if [ "${1:-}" = "--show-thread" ]; then
|
||||
shift
|
||||
thread="$1"
|
||||
res=$(__notmuch_thread "$thread" | $FZF \
|
||||
res=$(list_messages_in_thread "$thread" | $FZF \
|
||||
--raw \
|
||||
--reverse \
|
||||
--multi \
|
||||
@@ -91,6 +87,8 @@ if [ "${1:-}" = "--show-thread" ]; then
|
||||
--bind="ctrl-h,backward-eof:abort" \
|
||||
--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}" \
|
||||
--preview="$0 --preview-message {5}" \
|
||||
--preview-window="$FZF_DEFAULT_PREVIEW_WINDOW" || true)
|
||||
exit
|
||||
@@ -108,7 +106,7 @@ CMD_EDIT_QUERY="edit-query"
|
||||
while true; do
|
||||
nmquery="${nmquery:-tag:inbox}"
|
||||
[ "$(tail -1 "$NMFHIST")" = "$nmquery" ] || echo "$nmquery" >> "$NMFHIST"
|
||||
cmd=$(__notmuch_search "$nmquery" | $FZF \
|
||||
cmd=$(list_threads "$nmquery" | $FZF \
|
||||
--header="Query: $nmquery" \
|
||||
--tiebreak=index \
|
||||
--reverse \
|
||||
@@ -127,12 +125,14 @@ while true; do
|
||||
--bind='page-up:preview-half-page-up,page-down:preview-half-page-down' \
|
||||
--bind="enter,ctrl-l:execute:$0 --show-thread {4}" \
|
||||
--bind="alt-/:change-preview-window($FZF_ALTERNATE_PREVIEW_WINDOW|$FZF_DEFAULT_PREVIEW_WINDOW)" \
|
||||
--bind="alt-h:change-preview:$0 --preview-html-thread {4}" \
|
||||
--bind="focus:change-preview:$0 --preview-thread {4}" \
|
||||
--preview="$0 --preview-thread {4}" \
|
||||
--preview-window="$FZF_DEFAULT_PREVIEW_WINDOW" | head -1 || true)
|
||||
[ -n "$cmd" ] || exit 0
|
||||
case "$cmd" in
|
||||
$CMD_SEARCH_TAG*)
|
||||
tag=$(__notmuch_list_tags | $FZF \
|
||||
tag=$(list_tags | $FZF \
|
||||
--color="border:$ANSICOLORTAGS" \
|
||||
--color="label:$ANSICOLORTAGS" \
|
||||
--tac \
|
||||
@@ -155,7 +155,7 @@ while true; do
|
||||
field='to'
|
||||
;;
|
||||
esac
|
||||
address=$(__notmuch_list_address | $FZF \
|
||||
address=$(list_addresses | $FZF \
|
||||
--color="border:$ANSICOLORFROM" \
|
||||
--color="label:$ANSICOLORFROM" \
|
||||
--tiebreak=index \
|
||||
@@ -175,7 +175,7 @@ while true; do
|
||||
esac
|
||||
;;
|
||||
$CMD_EDIT_QUERY*)
|
||||
nmquery=$($FZF \
|
||||
nmquery=$(list_query_history | $FZF \
|
||||
--color="border:$ANSICOLORSUBJ" \
|
||||
--color="label:$ANSICOLORSUBJ" \
|
||||
--tac \
|
||||
@@ -187,7 +187,7 @@ while true; do
|
||||
--prompt="Query: " \
|
||||
--bind='focus:replace-query' \
|
||||
--border=double \
|
||||
--border-label=' Query history ' < "$NMFHIST" | head -1 || true)
|
||||
--border-label=' Query history ' | head -1 || true)
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
|
||||
Reference in New Issue
Block a user