How to fix a tmux session messed up by control characters

6,959

Solution 1

There is a detailed explication how to reset many parts of tmux in stack exchange: https://unix.stackexchange.com/questions/49886/tmux-status-bar-corrupted-after-catting-a-binary-file-how-to-reset

For me, often only tmux rename-window myWindowName and printf '\033]2;%s\007' "$(uname -n) (set status right) are required.

Solution 2

3 options...

  1. stty sane
  2. reset
  3. echo ^v^o (that's E

Solution 3

Ctrl+B then r should do it. This causes tmux to redraw the entire screen from scratch.

Solution 4

ctrl-b r is not the right answer. The right answer is:

  1. ctrl-b shift-D to get a list of the attached sessions
  2. select the session that you were using when you messed up the screen, and press Enter to detach it (or iterate through this list and detach from all sessions, if you prefer)
  3. if detached from all sessions in #2, then tmux attach -t again to attach a brand new session. This will get rid of the problematic session without having to terminate tmux.
Share:
6,959
Server Fault
Author by

Server Fault

Updated on September 18, 2022

Comments

  • Server Fault
    Server Fault over 1 year

    Every once in awhile, I'll accidentally blast some control codes into my terminal session (either errant coding or accidentally gpg --export). This sometimes causes my tmux session to loose it's formatting and print control characters into the borders of the tmux windows. All the tmux windows get pretty messed up after than. Even just focusing a window messes up the other windows. The traditional reset tricks for a terminal (reset, echo [CTRL]+V [CTRL]+C) don't fix it so I end up logging out of all active sessions and having to restart tmux.

    Anyone know of a way to reset/refresh all the tmux panes without terminating tmux ?

  • Server Fault
    Server Fault over 5 years
    Good idea, but no luck.
  • Michael Hampton
    Michael Hampton over 5 years
    Huh. You know, I can't even get my GNOME terminal with tmux to go haywire like that anymore, not even by deliberately catting binary files to it. Maybe it's time for some upgrades?
  • Server Fault
    Server Fault over 5 years
    Hrm.. I am using xfce4-terminal. Maybe that's the problem. If you don't mind, try gpg --export. That usually does it.
  • Michael Hampton
    Michael Hampton over 5 years
    Tried gpg --export. GNOME terminal 3.30 just laughs it off, in or out of tmux.
  • Server Fault
    Server Fault over 5 years
    Likely something with my setup or tmux verson. I'm running Ubuntu 16.04 and this happens with xterm, LXterminal and xfce4-terminal. I'll see if I can root it out. Thanks for your time.
  • Server Fault
    Server Fault over 5 years
    I'm just going to accept this as the answer because in typical circumstances, ctrl+b r is how to do it
  • Michael Hampton
    Michael Hampton over 5 years
    I do know what you're talking about though, I just can't recall experiencing it in a few years. I do run Fedora as my workstation though, so I'm usually on the latest or nearly latest code. Maybe it's time to upgrade?
  • Server Fault
    Server Fault over 5 years
    Upgrade may fix it. I usually run my workstation on the same OS our servers run so kind of married to 16.04 at the moment.
  • Server Fault
    Server Fault over 5 years
    Can't seem to get this to work either. When I tmux attach -t 0 the session is still corrupt from the gpg --export output
  • Server Fault
    Server Fault over 5 years
    Thanks, this works! stty sane; printf '\033k%s\033\\\033]2;%s\007' "basename "$SHELL"" "uname -n"; tput reset; tmux refresh