wangp / bower

A curses terminal client for the Notmuch email system
Other
119 stars 11 forks source link

Copy thread or message ID #44

Closed wangp closed 5 years ago

wangp commented 5 years ago

A useful feature would be to copy the current thread or message ID to the X primary selection or clipboard. The actual copying would be done by calling xclip or other tool. I'm considering moving the verify signature command from y to something else, say Y. Then we can take y for "yank" and have:

y t yank current thread ID
y y yank current message ID
' y yank selected message IDs
" y yank selected message IDs and unselect

(I'm not really happy with the ' and " prefixes but that's for another time.)

This feature would help with running notmuch commands outside of bower, e.g. to pipe the results into git am.

This feature could be generalised by prompting for a command to run, with the thread or message IDs passed as arguments (rather than piped in). It doesn't seem worthwhile, though.

vivien commented 5 years ago

Well the X selections are... X specific and I'm not sure I like that. For instance on Wayland that is not (natively) available (even though xclip works by the mean of the Xwayland compatible layer.)

Most TUI applications implement their own syntax for built-in variable such as git am %(bower-message-id) but I'm not fond of this approach. Bower is simpler yet more practical than that ;-)

Another interface I'm thinking about is piping the selected thread/message ID(s) to the standard input of a prompted command. This would allow one to still yank with xclip, as echo foo | xclip does, and pass it as argument(s) to e.g. xargs git am, as echo id:foo id:bar | xargs notmuch show --format=mbox | git am.

This makes even more sense to me with Bower's ability to select individual messages. That way we can select the patches of a thread intuitively without having to write a complex script skipping the cover letter or the non-patch replies within that thread.

wangp commented 5 years ago

I've implemented a version of this on the yank branch. The verify action has been moved to Y. To pipe the current or selected thread/message IDs, press y [followed by t or m in the thread view], then enter the command to receive IDs on standard input. The default command is xclip but it is configurable.

Let me know if you have better ideas for a key binding. Maybe we should take | for this after all.

vivien commented 5 years ago

Hi Wang,

I tried the yank branch without success. I first try y then typing while read id ; do notmuch show --format=mbox $id | git am -3 ; done but this results in unknown result code from system command. I tried to put that in a script and pipe to ./notmuch-apply but this doesn't result in any message.

What am I doing wrong?

Regarding y vs. |, whatever suits you is good for me, even though I have a preference for | which is more idiomatic.

It would be also nice to have a better feedback (maybe a color? message? return code?) whether the pipe commands succeed or not.

wangp commented 5 years ago

The IDs are separated by spaces and not terminated with a newline, so the read id command is unable to read the line. This script accepts IDs on standard input or as command line arguments:

 #!/bin/sh
set -eu
if [ $# = 0 ]; then
    set -- $(cat)
fi
notmuch show --format=mbox "$@" | git am -3

Separating IDs by spaces and not terminating with newline seems more convenient when copying to a clipboard. My idea is that you have another terminal with a shell open in your project's working directory, then you can copy the IDs and paste them into a shell command. I think calling git am in a shell makes more sense as you can deal with any errors that arise.

BTW, to run a shell command you need to invoke the shell explicitly, e.g. sh -c 'notmuch-apply 2>&1 | less'

Correction: read can read a line without newline but it returns false. http://mywiki.wooledge.org/BashFAQ/001#My_text_files_are_broken.21__They_lack_their_final_newlines.21

wangp commented 5 years ago

Merged an updated version of this to master, bound to | instead of y.