nmh-workers
[Top] [All Lists]

Re: X/browser-based mime-types

2021-05-13 05:31:39
Hi Michael,

I do this in .mh_profile via:
  mhshow-show-text/html: google-chrome '%f'

although sometimes the file goes missing before the browser can
display it.  (It won't do that to me now that I try to reproduce
it...)

You'll probably find the google-chrome you start above spots another is
running and passes the job of opening the file to it and then exits.
nmh takes the exit of the google-chrome it started as the signal to
remove the temporary file.  It's a race between nmh's removal and the
already running google-chrome's opening of the file.  Stall the old
google-chrome to increase the chance of it losing the race.

But, I also login to my desktop from my laptop via ssh (and
X-forwarding-challenged mosh, sigh).

mosh looks unloved.  screen(1) on the desktop would be an alternative,
but you probably know that.

Has anyone come up with version of "open this URL" (or open this file)
that will talk through the forwarded X connection, and get *that*
browser to open the link, rather than use some browser shortcut that
opens it on the wrong desktop?

Here's the methods I can think of...

To use the forwarded X connection as you request, where desktop programs
like xclock(1) display on the laptop, an X client on the laptop would
open the laptop X server's display and listen for PropertyNotify events
on the root window.  The property its monitoring would be a new one
agreed with and set by the X client run on the desktop by
‘mhshow-show-text/html’ but forwarded to the laptop's X server.  When
the PropertyNotify event arrives then a local xdg-open(1) or
google-chrome(1) is run to open the URL, assuming it's accessible from
the laptop.  See XChangeProperty(3) or xcb_change_property_checked(3).
You can probably cobble together a couple of shell scripts to do this
using xprop(1), which is pretty capable, and xev(1).

Have your SSH connection from laptop to desktop set up a reverse tunnel
which allows the desktop ‘mhshow-show-text/html’ program to communicate
to the laptop.  This may be sending the URL to a simple server which
listens on the laptop's localhost interface and opens the URLs it
receives.  socat(1) would do, or programs like bash(1) and gawk(1)
provide /dev/tcp/host/port style access for scripting, assuming your
distro isn't still disabling them as Debian did.  You could even have an
SSH server on the laptop and run ssh on the desktop to run xdg-open(1)
on the laptop but it would have to find a way to connect to the laptop's
X server.

It may be possible to use DBUS to achieve this, but with no more
simplicity than the above approaches AFAICS.  I can't find any DBUS
specification which suggests opening URLs is done through it.  Instead,
programs like xdg-open will poke about your preferences and run
exo-open(1) or the Gnome equivalent, and that seems to kick off the
program directly.

Have you considered VNC?  With modern connection speeds and improvements
to the protocol it's a lot better now than the last time you may have
tried it.  Using TigerVNC, I can have an X session on the desktop, or
any powerful server, which doesn't have a physical screen associated
with it, and then connect to it from elsewhere.  The X server will
resize to match the VNC client's window on the fly, and the client can
go full screen with no window borders so I'm effectively sitting at the
remote machine.  Also, the session doesn't end when the client closes so
I can move physically, and to a different device with a different screen
size for the client, reconnect, and it's all as I left it.  Some useful
info:
https://wiki.archlinux.org/title/Vnc#Running_vncserver_for_virtual_(headless)_sessions

-- 
Cheers, Ralph.

<Prev in Thread] Current Thread [Next in Thread>