wangp / bower

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

REQ: "Print" #108

Closed xxxserxxx closed 1 year ago

xxxserxxx commented 1 year ago

I started trying to add this myself, but I'm concerned that I won't do the shelling part correctly, so I'm just going to submit a request.

I'd like to be able to print emails. That is, I'd like to bind a key that prints a single selected message, probably from the thread view since that's where most of this sort of stuff happens right now.

My suggestion

This is a script that I'm currently calling with the pipe command. It works, but it's a bit fussy since I do several things with the pipe command and bower allows setting one default; this means typing the command nearly every time.

The script depends on the tool email2pdf, which is a package in Arch and so is probably available on other releases. It wouldn't be the first external tool bower ships needing for some functionality.

The script is probably reducible within code. The first read gets the message ID from STDIN, which is how it seems bower passes arguments to shells. The Mercury ABI probably allows setting env variables, which is how I'd probably do it, but I didn't want to stray too much from the whole pipe_to.m idiom set up by bower. I use tempname to create a temporary file, because email2pdf doesn't know how to pipe. tempname is the tool Arch deploys with; Debian deploys with tempfile, but it does the same thing with different arguments. If it were me, I'd create the temp file name in code, in Bower, not shell it out.

read MID
FPATH="$(notmuch search --exclude=false --output=files $MID)"
FOUT="$(tempname -c -s pdf bower)"
email2pdf -i "$FPATH" -o "$FOUT"
lp "$FOUT"
rm "$FOUT"

As I said, this was a bit much for me to try to cram into pipe_to.m; there were no examples more complex than trivial call-outs, and since I'm just copy/pasting it was a recipe for disaster.

Ideally, the printer name would be a prompted option with a default, or at least a config file option (lp -d $PRINTER $FOUT).

wangp commented 1 year ago

You could use the "Open with command" function. Highlight the message with V then run a command with o. Your command will receive the path to a temporary file containing the message contents.

I wouldn't add specific functionality for this, but maybe we can pre-populate the input history with multiple commands to save some typing. Something like:

# Multiple commands are allowed when separated by semicolon.
open_part = xdg-open& ; print-email
xxxserxxx commented 1 year ago

Does the semicolon trick also work with pipe? I assume this gives you some sort of selectable functionality to prevent extraneous typing if you use many external commands.

wangp commented 1 year ago

When you are prompted for a command to run, you would press up arrow to select the command in the history, as if you had typed it previously.

wangp commented 1 year ago

I've pushed the change to support multiple commands on open_part, open_url and pipe_id.

xxxserxxx commented 1 year ago

Thanks, I'll close this.