nixpkgs-ml-tools

nixpkgs mailing list tools
git clone git://jb55.com/nixpkgs-ml-tools
Log | Files | Refs | README | LICENSE

commit 0f8c876d0e060fc0793a16ea124d452e0b581f02
parent 159fe820d4a0cb420fe89c2d133f0ceb1cdef1a3
Author: Matthias Beyer <mail@beyermatthias.de>
Date:   Sun, 18 Apr 2021 16:14:43 +0200

Revert "Revert "Add fuzzy-patch-thread-selecting""

This reverts commit 159fe820d4a0cb420fe89c2d133f0ceb1cdef1a3.

Diffstat:
Mnotmuch-am | 28+++++++++++++++++++++++++---
1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/notmuch-am b/notmuch-am @@ -30,6 +30,7 @@ _positionals=() _arg_am="off" _arg_3="off" _arg_amsignoff="off" +_arg_fuzzy="off" print_help() @@ -40,6 +41,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 "\ @@ -82,6 +84,9 @@ parse_commandline() -l|--add-link) _arg_b4addlink="on" ;; + --fuzzy) + _arg_fuzzy="on" + ;; *) _last_positional="$1" _positionals+=("$_last_positional") @@ -96,8 +101,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 } @@ -155,5 +164,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"