Reattaching tmux to your Xorg session
This post's featured URL for sharing metadata is https://www.jvt.me/img/profile.jpg.
It happens infrequently enough to not investigate too much further, but sometimes I'll end up with my Xorg/X11 session crashing, or something else happening which leads to my existing tmux sessions failing to interact with the new X session, with errors like:
% gh repo view --web
Opening ... in your browser.
Error: cannot open display: :0
% xsel
xsel: Can't open display: (null)
: Connection refused
In this case, the existing panes/windows may end up seeing a related error about failing to connect to the display, but any new panes/windows created will be able to interact as expected.
This is a bit of an annoying one, but one way we can solve this is to nudge these panes to use the new DISPLAY. In a new pane/window/terminal session, check the DISPLAY environment variable:
% echo $DISPLAY
:1
That's likely different to what it shows in one of those existing panes - if so, run:
% export DISPLAY=:1
After which, you can then run commands that interact with your X session.
It's possible to run:
% tmux set-environment DISPLAY :0
Which will update all new panes - but as mentioned, tmux likely already handled that for you, as DISPLAY is one of the environment variables it updates, as per:
% tmux show-options -g update-environment
update-environment[0] DISPLAY
...
Instead of doing this by hand, it's also possible (Via) to script this to ??.