commit e5661eb80b5cff0dc2ec29fc199557339289aa72
parent 86e142750a20ddb9841899c9cd7af3eb3a7ddfeb
Author: Matthias Beyer <mail@beyermatthias.de>
Date: Thu, 1 Apr 2021 20:39:49 +0200
Add fuzzy-patch-thread-selecting
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Tested-by: Matthias Beyer <mail@beyermatthias.de>
Link: https://lore.kernel.org/r/20210401183949.25894-6-mail@beyermatthias.de
Diffstat:
1 file changed, 25 insertions(+), 3 deletions(-)
diff --git a/notmuch-am b/notmuch-am
@@ -28,6 +28,7 @@ _positionals=()
_arg_am="off"
_arg_3="off"
_arg_amsignoff="off"
+_arg_fuzzy="off"
print_help()
@@ -38,6 +39,7 @@ print_help()
printf '\t%s\n' "--am, --no-am: Call git-am instead of generating a mbox file (off by default)"
printf '\t%s\n' "-3: Call git-am with -3 (off by default, only effective with --am)"
printf '\t%s\n' "-s, --signoff: Call git-am with --signoff (off by default, only effective with --am)"
+ printf '\t%s\n' "--fuzzy: Use fzf to interactively select the thread for the patchset to apply"
printf '\t%s\n' "-h, --help: Prints help"
printf %s "\
@@ -77,6 +79,9 @@ parse_commandline()
-s|--signoff)
_arg_amsignoff="on"
;;
+ --fuzzy)
+ _arg_fuzzy="on"
+ ;;
*)
_last_positional="$1"
_positionals+=("$_last_positional")
@@ -91,8 +96,12 @@ parse_commandline()
handle_passed_args_count()
{
local _required_args_string="'thread-id'"
- test "${_positionals_count}" -ge 1 || _PRINT_HELP=yes die "FATAL ERROR: Not enough positional arguments - we require exactly 1 (namely: $_required_args_string), but got only ${_positionals_count}." 1
- test "${_positionals_count}" -le 1 || _PRINT_HELP=yes die "FATAL ERROR: There were spurious positional arguments --- we expect exactly 1 (namely: $_required_args_string), but got ${_positionals_count} (the last one was: '${_last_positional}')." 1
+ if [[ "${_positionals_count}" -ge 1 ]] && [[ "$_arg_fuzzy" == "off" ]]; then
+ _PRINT_HELP=yes die "FATAL ERROR: Not enough positional arguments - we require exactly 1 (namely: $_required_args_string), but got only ${_positionals_count}." 1
+ fi
+ if [[ "${_positionals_count}" -le 1 ]] && [[ "$_arg_fuzzy" == "off" ]]; then
+ _PRINT_HELP=yes die "FATAL ERROR: There were spurious positional arguments --- we expect exactly 1 (namely: $_required_args_string), but got ${_positionals_count} (the last one was: '${_last_positional}')." 1
+ fi
}
@@ -146,5 +155,18 @@ main () {
rm -f "$mbox"
}
-[ -n "$1" ] || usage && main "$_arg_thread_id"
+thread_id="$_arg_thread_id"
+
+if [[ "$_arg_fuzzy" == "on" ]]; then
+ preview_script='echo {} | sed "s,\t.*,,; s,^,thread:," | xargs notmuch search --output=files --format=text | xargs grep -ihE "^Subject" | sort'
+
+ user_email="$(git config user.email)"
+
+ thread_id=$(notmuch search --output=summary --format=json "to:$user_email" and subject:PATCH | \
+ jq -rcC '.[] | [.thread,.date_relative,.subject,.authors] | @tsv' | \
+ fzf -m --preview "$preview_script" | \
+ sed 's,\t.*,,; s,^,thread:,')
+fi
+
+[ -n "$1" ] || usage && main "$thread_id"