Tmux

2021-04-29

  • 1 Basics
    • 1.1 Installation
    • 1.2 Manually Reload Config
  • 2 Advanced
    • 2.1 Update DISPLAY

1 Basics

1.1 Installation

Download sources from Github.

mkdir build
cd build
LIBEVENT_CORE_CFLAGS="-I$HOME/Softwares/libevent/include" LIBEVENT_CFLAGS="-I$HOME/Softwares/libevent/include" LIBEVENT_CORE_LIBS="-L$HOME/Softwares/libevent/lib -levent_core" LIBEVENT_LIBS="-L$HOME/Softwares/libevent/lib -levent" ../configure --prefix=$HOME/Softwares/tmux-3.2
make
make install

1.2 Manually Reload Config

source ~/.tmux.conf

2 Advanced

2.1 Update DISPLAY

The problem: When you ssh -X into a machine and attach to an existing tmux session, the session contains the old $DISPLAY env variable. In order the x-server/client to work properly, you have to update $DISPLAY after connection. For example, the old $DISPLAY=:0 and you need to change to $DISPLAY=localhost:10.0 for my ssh session to perform x-forwarding properly.

The solution: When attaching to tmux session, update $DISPLAY for each tmux pane in that session. This is performed by using tmux send-keys to the shell, so unfortunately $DISPLAY will not update for other active processes (vim, top, etc…) Keep this file in your $PATH, so you can run update these panes manually later

Add to tmux.conf:

set-hook -g client-attached 'run-shell /bin/update_display.sh'

Create 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

Note: tmux 2.9 does not recognize DISPLAY. You need to use tmux 3.2.

.
Created on 2021-04-29 with pandoc