gpakosz / .tmux

🇫🇷 Oh my tmux! My self-contained, pretty & versatile tmux configuration made with ❤️
MIT License
21.73k stars 3.34k forks source link

default-terminal not being honoured in .tmux.conf.local #656

Closed Kristijan closed 1 year ago

Kristijan commented 1 year ago

I have set-option -g default-terminal "xterm-256color" in my .tmux.conf.local file, but it doesn't appear to be honoured when starting up tmux on my RHEL server. After startup, the $TERM variable is set to tmux-256color.

I've done some digging around using git bisect, and narrowed the change in behaviour being caused by this commit - https://github.com/gpakosz/.tmux/commit/044d6336e84034c14760a2fe178f604a89626bfb

Would it be possible to have some logic in the _apply_tmux_256color function that only sets default-terminal if it's not already explicitly set via .tmux.conf.local?

gpakosz commented 1 year ago

Hello @Kristijan 👋

As per tmux FAQ, TERM inside of tmux should be either screen-256color or tmux-256color, not xterm-256color.

From there here's what you can do:

Kristijan commented 1 year ago

Thanks @gpakosz, that last option provided has helped! Appreciate the quick response.

flakrat commented 1 year ago

@Kristijan thanks for opening this issue, found it because I was having a similar problem after the latest git pull.

@gpakosz thanks for the solution.

Some notes on what got me to this issue in case it helps others troubleshoot.

Workflow, I SSH to a remote server and start or attach to Tmux (using this repo's ~/.tmux.conf). Following the latest git pull I started getting odd TERM and DISPLAY errors when running commands via sudo:

Example using sudo less:

$ echo $TERM
tmux-256color

$ sudo less /var/log/messages
WARNING: terminal is not fully functional
/var/log/messages  (press RETURN)

Another example when attempting to run Dell's dsu command (firmware update tool) against a remote client server to the one where Tmux is running:

$ sudo ansible c01 -m shell -a '/usr/sbin/dsu -q -u --import-public-key
...
xterm: Xt error: Can't open display: %s
xterm: DISPLAY is not set
...
        648ed6eb-7a13-4d31-9507-77b33108ad97  | 10-07-2023 11:12:18  |  FATAL   |       Inventory file not found - /usr/libexec/dell_dup/inv.xml

The solution @gpakosz solved the issue after killing the Tmux session and starting a new one. I did have that in my ~/.tmux.conf.local, however the line following it was causing problems (since removed):

diff --git a/tmux/.tmux.conf.local b/tmux/.tmux.conf.local
index 7b865f3..859ecc0 100644
--- a/tmux/.tmux.conf.local
+++ b/tmux/.tmux.conf.local
@@ -456,7 +456,6 @@ set -s escape-time 0
 #   less /var/log/messages
 #   WARNING: terminal is not fully functional
 set -g default-terminal "screen-256color"
-set -ga terminal-overrides ",xterm-256color:Tc"

 # Disabling the default setting in https://github.com/gpakosz/.tmux.git .tmux.conf
 set -g renumber-windows off    # don't renumber windows when a window is closed
gpakosz commented 1 year ago

@flakrat You're mentioning SSH and SSH sends the TERM environment variable to the remote host. You can override that in your ~/.ssh/config with

Host example.com
  SetEnv TERM=xterm-256color