Send a command to a running tmux session (like screen -X)

It's just tmux, optionally with the -t option to select a session (corresponding to -S for Screen).

tmux set-environment DISPLAY $DISPLAY

Answering the part of the question about updating the environment: tmux by default inherits certain variables from the client's environment when creating or reattaching a session.

From the manpage:

The update-environment session option may be used to update the session environment from the client when a new session is created or an old reattached.

The default is "DISPLAY SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION WINDOWID XAUTHORITY".

So you don't have to do anything to get the updated DISPLAY setting when reattaching a session.

Note that this only takes effect for new windows or panes you create in the old session, but not existing windows.


If you're looking to update $DISPLAY automatically for each of your shell processes in your tmux session, you can check out my solution: https://www.reddit.com/r/tmux/comments/cd3jqw/automatically_update_display_for_each_tmux_pane/

To summarize:

Add line to tmux.conf set-hook -g client-attached 'run-shell /bin/update_display.sh'

Create script /bin/update_display.sh:

# tmux will only send-keys to the following active processes
shell_grep="bash|zsh"

# Update $DISPLAY for each tmux pane that is currently running one of the $shell_grep processes
tmux list-panes -s -F "#{session_name}:#{window_index}.#{pane_index} #{pane_current_command}" | \
    grep -E $shell_grep| \
    cut -f 1 -d " " | \
    xargs -I PANE tmux send-keys -t PANE 'eval $(tmux showenv -s DISPLAY)' Enter