* lei q: --stdin confuses --mua
@ 2021-04-17 15:53 Kyle Meyer
2021-04-17 16:04 ` Kyle Meyer
2021-04-17 19:00 ` [PATCH] lei q: fix MUA spawn after reading query from stdin Eric Wong
0 siblings, 2 replies; 4+ messages in thread
From: Kyle Meyer @ 2021-04-17 15:53 UTC (permalink / raw)
To: meta
I used `lei p2p' to track down an associated thread recently. It worked
nicely, though I noticed that I wasn't able to jump straight into mutt
via --mua.
Here's an example using public-inbox.git. Feeding the p2q output on
stdin, I'm told that no recipients were specified, and the command exits
rather than dropping me into mutt's interface.
$ lei p2q 8ab43c1c27c725a8ef9307f5dba3e565169d48ca | \
lei q -q -tt - -o mboxcl2:/tmp/t.mbox --mua=mutt
No recipients were specified.
I'm not a mutt user, but I think that's because mutt sees that stdin
isn't attached to a tty. I haven't tried anything on my end yet, but
perhaps there's a clean way to make --stdin and --mua [*] work together.
Thoughts?
[*] The only other --mua value I checked was 'mail' (and that shows a
similar issue), but I'm guessing other MUAs don't not work well
with --stdin either.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: lei q: --stdin confuses --mua
2021-04-17 15:53 lei q: --stdin confuses --mua Kyle Meyer
@ 2021-04-17 16:04 ` Kyle Meyer
2021-04-17 19:00 ` [PATCH] lei q: fix MUA spawn after reading query from stdin Eric Wong
1 sibling, 0 replies; 4+ messages in thread
From: Kyle Meyer @ 2021-04-17 16:04 UTC (permalink / raw)
To: meta
Kyle Meyer writes:
> [*] The only other --mua value I checked was 'mail' (and that shows a
> similar issue), but I'm guessing other MUAs don't not work well
guh, that's a confusing typo: s/don't not/don't/
> with --stdin either.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] lei q: fix MUA spawn after reading query from stdin
2021-04-17 15:53 lei q: --stdin confuses --mua Kyle Meyer
2021-04-17 16:04 ` Kyle Meyer
@ 2021-04-17 19:00 ` Eric Wong
2021-04-17 20:13 ` Kyle Meyer
1 sibling, 1 reply; 4+ messages in thread
From: Eric Wong @ 2021-04-17 19:00 UTC (permalink / raw)
To: Kyle Meyer; +Cc: meta
Kyle Meyer <kyle@kyleam.com> wrote:
> I'm not a mutt user, but I think that's because mutt sees that stdin
> isn't attached to a tty. I haven't tried anything on my end yet, but
> perhaps there's a clean way to make --stdin and --mua [*] work together.
Thanks for the report. Yes, that's correct, fortunately we can
reasonably expect stdout to be a terminal and the patch below
should fix it.
> [*] The only other --mua value I checked was 'mail' (and that shows a
> similar issue), but I'm guessing other MUAs don't not work well
> with --stdin either.
Btw, since you seem to be a gnus user; does/can gnus work
via --mua= ?
----------8<---------
Subject: [PATCH] lei q: fix MUA spawn after reading query from stdin
Since "lei q" may read queries from stdin, we must reconnect a
known terminal before spawning terminal MUAs. Attempt to use
stdout as stdin for this purpose, since terminal MUAs tend to
expect stdout to be a terminal.
Reported-By: Kyle Meyer <kyle@kyleam.com>
Link: https://public-inbox.org/meta/87v98klxg3.fsf@kyleam.com/
---
lib/PublicInbox/LEI.pm | 10 ++++++++--
script/lei | 12 ++++++------
2 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index ebd0f154..f223b3de 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -840,11 +840,17 @@ sub start_mua {
@cmd = map { $_ eq '%f' ? ($replaced = $mfolder) : $_ } @cmd;
}
push @cmd, $mfolder unless defined($replaced);
- if (my $sock = $self->{sock}) { # lei(1) client process runs it
- send($sock, exec_buf(\@cmd, {}), MSG_EOR);
+ if ($self->{sock}) { # lei(1) client process runs it
+ # restore terminal: echo $query | lei q -stdin --mua=...
+ my $io = [];
+ $io->[0] = $self->{1} if $self->{opt}->{stdin} && -t $self->{1};
+ send_exec_cmd($self, $io, \@cmd, {});
} elsif ($self->{oneshot}) {
my $pid = fork // die "fork: $!";
if ($pid > 0) { # original process
+ if ($self->{opt}->{stdin} && -t STDOUT) {
+ open STDIN, '+<&', \*STDOUT or die "dup2: $!";
+ }
exec(@cmd);
warn "exec @cmd: $!\n";
POSIX::_exit(1);
diff --git a/script/lei b/script/lei
index 76217ab9..56e9d299 100755
--- a/script/lei
+++ b/script/lei
@@ -33,6 +33,9 @@ my $exec_cmd = sub {
push @rdr, shift(@old), $newfh;
}
my $do_exec = sub {
+ while (my ($io, $newfh) = splice(@rdr, 0, 2)) {
+ open $io, '+<&', $newfh or die "open +<&=: $!";
+ }
my %env = map { split(/=/, $_, 2) } splice(@argv, $argc);
@ENV{keys %env} = values %env;
exec(@argv);
@@ -42,20 +45,17 @@ my $exec_cmd = sub {
$SIG{CHLD} = $sigchld;
my $pid = fork // die "fork: $!";
if ($pid == 0) {
- while (my ($io, $newfh) = splice(@rdr, 0, 2)) {
- open $io, '+<&', $newfh or die "open +<&=: $!";
- }
- $do_exec->() if scalar(@$fds); # git-credential, pager
+ $do_exec->() if $fds->[1]; # git-credential, pager
# parent backgrounds on MUA
POSIX::setsid() > 0 or die "setsid: $!";
@parent = ($parent);
return; # continue $recv_cmd in background
}
- if (scalar(@$fds)) {
+ if ($fds->[1]) {
$pids{$pid} = undef;
} else {
- $do_exec->(); # MUA reuses all FDs
+ $do_exec->(); # MUA reuses stdout
}
};
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] lei q: fix MUA spawn after reading query from stdin
2021-04-17 19:00 ` [PATCH] lei q: fix MUA spawn after reading query from stdin Eric Wong
@ 2021-04-17 20:13 ` Kyle Meyer
0 siblings, 0 replies; 4+ messages in thread
From: Kyle Meyer @ 2021-04-17 20:13 UTC (permalink / raw)
To: Eric Wong; +Cc: meta
Eric Wong writes:
> Kyle Meyer <kyle@kyleam.com> wrote:
>> I'm not a mutt user, but I think that's because mutt sees that stdin
>> isn't attached to a tty. I haven't tried anything on my end yet, but
>> perhaps there's a clean way to make --stdin and --mua [*] work together.
>
> Thanks for the report. Yes, that's correct, fortunately we can
> reasonably expect stdout to be a terminal and the patch below
> should fix it.
Confirmed. Thanks for the quick fix.
>> [*] The only other --mua value I checked was 'mail' (and that shows a
>> similar issue), but I'm guessing other MUAs don't not work well
>> with --stdin either.
>
> Btw, since you seem to be a gnus user;
I'm a lightweight Gnus user :) I just use gnus to read NNTP, and use
Notmuch for mail. But...
> does/can gnus work via --mua= ?
... I don't see a good way to do this, no. A more natural approach
would be calling lei from Emacs.
I've been thinking a good amount about Emacs integration with lei in the
context of piem (<https://git.kyleam.com/piem/>). My initial focus will
be something closer to Notmuch's Emacs interface. I'm pretty excited
about the it, as it will be the main way I interact with lei (but sadly
it'll be at least a few weeks before I have the free time to begin any
work on it).
The above interface will probably reduce my use of Gnus to lists that
don't have public-inbox archives, but I still might try to add some Gnus
integration eventually. Gnus has a mairix backend, so that'd be the
first placed I'd study for approaching integration.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-04-17 20:14 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-04-17 15:53 lei q: --stdin confuses --mua Kyle Meyer
2021-04-17 16:04 ` Kyle Meyer
2021-04-17 19:00 ` [PATCH] lei q: fix MUA spawn after reading query from stdin Eric Wong
2021-04-17 20:13 ` Kyle Meyer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).