tmux-plugins / tmux-continuum

Continuous saving of tmux environment. Automatic restore when tmux is started. Automatic tmux start when computer is turned on.
MIT License
3.24k stars 149 forks source link

XAUTHORITY environment variable is not set when using automatic tmux start with systemd #129

Open ariel-miculas opened 11 months ago

ariel-miculas commented 11 months ago

The feature is desribed here

The issue prevents me (among other things) from copying text using xclip:

$ alias cb
cb='xclip -sel clip'
$ echo foobar | cb
Invalid MIT-MAGIC-COOKIE-1 key
Error: Can't open display: :0
$ xauth
Using authority file /home/amiculas/.Xauthority
xauth>

XAUTHORITY is empty in the tmux panes, but in a newly opened terminal it's set:

$ echo $XAUTHORITY
/tmp/xauth_cIHUDf
$ xauth
Using authority file /tmp/xauth_cIHUDf
xauth>   

It can be observed that xauth is using the default file ~/.Xautority in tmux, but it uses another file /tmp/xauth_cIHUDf in a newly opened terminal.

Systemd unit:

[Unit]
Description=tmux default session (detached)
Documentation=man:tmux(1)

[Service]
Type=forking
Environment=DISPLAY=:0
ExecStart=/usr/bin/tmux new-session -d

ExecStop=/home/amiculas/.tmux/plugins/tmux-resurrect/scripts/save.sh
ExecStop=/usr/bin/tmux kill-server
KillMode=control-group

RestartSec=2

[Install]
WantedBy=default.target

Systemd service:

$ systemctl --user status tmux.service
● tmux.service - tmux default session (detached)
     Loaded: loaded (/home/amiculas/.config/systemd/user/tmux.service; enabled; preset: enabled)
     Active: active (running) since Mon 2023-10-16 17:29:59 EEST; 10min ago
       Docs: man:tmux(1)
   Main PID: 1180 (tmux: server)
      Tasks: 1396 (limit: 18804)
     Memory: 5.8G
        CPU: 3min 17.858s

Probably related to https://github.com/tmux-plugins/tmux-resurrect/issues/332

MagnetizedFreckles commented 10 months ago

Hello, I just wanna say that this exact issue happens for me

Chris-zerocopy commented 4 months ago

Yes - I'd like to upvote this issue as well.

It prevents me from using xclip in any of the tmux panes or sessions I have open