Complete tmux reset - macos

I was wondering if it is possible to completely reset tmux (the UI mainly) ?
I have tried deleting my ~/.tmux.conf and reinstalling tmux it but I always ended up with the same status bar I had defined.

Had forgotten to kill the existing sessions:
tmux kill-server
was the solution (credits to: #Kent)

Related

Mouse reporting after losing connection to remote tmux session

This has been puzzling me for a while. I use tmux on a remote server via ssh. Tmux makes sure I don't have to worry about accidentally losing connection to the server. However, I found out every time I lost the connection, my terminal keeps reporting mouse interactions.
Losing connection to remote tmux session, will firstly give me this message client_loop: send disconnect: Broken pipe. After this, all mouse interaction within this
shell session will show following gibberish. It requires me to open another shell session to get rid of this behavior. This happens both to my macOS Terminal and another terminal emulator I'm using, kitty. Therefore I believe this is due to some bad configuration in my shell or tmux.
0;58;42M0;58;42m65;50;44M66;50;44M65;50;44M65;50;44M65;50;44M66;50;44M65;50;44M65;50;44M65;50;44M67;50;44M65;50;44M65;50;44M65;50;44M65;50;44M65;50;44M65;50;44M65;50;44M65;50;44M65;50;44M65;50;44M65;50;44M65;50;44M65;50;44M65;50;44M65;50;44M65;50;44M67;50;44M65;50;44M65;50;44M67;50;44M65;50;44M65;50;44M65;50;44M65;50;44M65;50;44M65;50;44M65;50;44M65;50;44M65;50;44M65;50;44M65;50;44M65;50;44M65;50;44M65;50;44M65;50;44M65;50;44M65;50;44M65;50;44M65;50;44M65;50;44M65;50;44M67;50;44M65;50;44M65;50;44M65;50;44M67;50;44M65;50;44M65;50;44M67;50;44M65;50;44M65;50;44M65;50;44M67;50;44M65;50;44M65;50;44M65;50;44M67;50;44M65;50;44M65;50;44M67;50;44M65;50;44M65;50;44M65;50;44M67;50;44M65;50;44M65;50;44M65;50;44M67;50;44M65;50;44M65;50;44M65;50;44M67;50;44M65;50;44M65;50;44M67;50;44M65;50;44M64;50;44M64;50;44M64;50;44M64;50;44M64;50;44M66;50;44M64;50;44M64;50;44M64;50;44M64;50;44M65;51;50M65;51;50M65;51;50M65;51;50M67;51;50M65;51;50M65;51;50M65;51;50M65;51;50M65;51;50M65;51;50M65;51;50M65;51;50M65;51;50M0;1;44M32;2;44M32;3;44M32;4;44M32;5;44M32;6;44M32;7;44M32;8;44M32;9;44M32;10;44M32;11;44M0;11;44m0;20;48M0;20;48m0;20;47M0;20;47m0;53;50M0;53;50m0;63;47M0;63;47m
My tmux version is 1.8. And the tmux.conf file has the following mouse related lines
# Use mouse
setw -g mode-mouse on
set -g mouse-select-window on
set -g mouse-select-pane on
set -g mouse-resize-pane on
set -g mouse-utf on
I'm wondering if anyone knows how to resolve this.
Many thanks in advance!

When creating tmux session through crontab, specifying the .bash_profile source path inside `tmux new session -d` command doesn't work

What am I trying to achieve?
I'm trying to get crontab to kill the previous tmux session and create a new tmux session (with particular teamocil settings).
Simple bash script that the crontab runs:
#!/bin/bash
tmux kill-session;
tmux new-session -d "source /home/qa/.bash_profile;teamocil settings;";
Issue I'm having?
Running this script manually works fine, but when running through crontab it will only work if at least 2 other tmux sessions pre-exist, i.e. it kills a session as part of the script, if there are then no sessions left the crontab won't create the 1st session. If after killing a session there is still another session available, then the script works.
Findings so far?
I've found that if I declare the source as part of the bash script, not in the tmux new sessions command, then it works fine. Why would this be? See modified script below that works:
#!/bin/bash
source /home/qa/.bash_profile
tmux kill-session;
tmux new-session -d "teamocil settings;";
It would be really helpful to understand why this made a difference, to help me update other scripts and not make this mistake again. Any light that can be shed on this is appreciated.
Put path to profile before path to script directly in crontab line, this will make script more flexible for future usage.
Explanation https://serverfault.com/questions/337631/crontab-execution-doesnt-have-the-same-environment-variables-as-executing-user
Very good answer https://unix.stackexchange.com/questions/27289/how-can-i-run-a-cron-command-with-existing-environmental-variables
another very good answer https://unix.stackexchange.com/questions/6790/executing-a-sh-script-from-the-cron
Recomendation:
There is probably answer to you question somewhere. One needs just to search for it.

tmux detach while running script

So I have a script that I would like to run on my server and not have it bother me. So I thought I would run the server in a tmux window and then detach it so I could simply attach if I ever want to look at the progress (this script will take days to run).
but when I run my script in the tmux window, I am not able to detatch while it is running. Is there something I am doing wrong? How can I detach while this still runs? I feel like I am being very oblivious to an obvious solution here.
You can detach from a tmux session while leaving the script running by:
CTRL + b, then pressing d
You can enter back into the session by running tmux attach -t <session id>

my tmux status bar has disappeared

While writing code inside a tmux session, I inadvertently pressed a sequence of keys that has made my status bar disappear.
I haven't touched my tmux config file, and I verified the status bar is visible in new tmux sessions. Disconnecting and reconnecting to this session didn't help.
Read through the man page and searched through Google, no luck so far.
Running the following commands from inside the session didn't help:
^B :set-option -g status-bg default
^B :set-option -g status on
I have many windows open and would prefer not to have to destroy this session. Any help would be appreciated.
From the tmux command line, issue:
:set status on
to turn the status bar on. You can simplify this by adding a line to your .tmux.conf:
# toggle statusbar
bind-key b set-option status
and then reload your config.
Not quite a solution, but a possible workaround.
I'll assume your old session is number 0; adjust the argument to -t as necessary.
tmux new-session -t 0
This creates a new session which has all the same windows as session 0. If you create a new window in one session, it appears in the other as well. If you delete a window from one, it is removed from the other. More importantly, the new session should have a status bar. Then, you can try removing the old status-free session:
tmux kill-session -t 0
This should not affect the windows in session 0, since they are all part of your new session as well.

How to reconnect to accidentally disconnected ssh session WITHOUT screen or tmux

I know these kinds of questions have been asked for years, and the answer to them are often Screen or tmux.
I surely will use screen at beginning if I know I will leave the session for a long time, or the network is too bad to maintain a reliable connection.
The main problem is when I start some session and find it must last long later, or the connection just lost accidentally. In the later case, often when I start another session immediately, I can find the previous processes are not killed at that time, but I just have no way to reconnect to their terminal.
So I wonder if it is possible to prevent normal processes from killed even long time after accidentally disconnected SSH session. And the most important is I can reconnect to their terminals with out start them in Screen in advance.
If not, is is possible to move a already started bare ssh session into a new Screen session for later reconnect?
I don't believe it's possible without something like screen. Once your pseudo-TTY is lost I'm almost certain it can't be recovered from a different shell (at least not without some narly hacks).
As far as adding an existing process to a new screen I think that is possible. Try the instructions here:
http://monkeypatch.me/blog/move-a-running-process-to-a-new-screen-shell.html
The first thing to do is to suspend the process. In my case, Irssi can be suspended by typing Ctrl + Z.
Secondly, resume the process in background:
$ bg
Now, we will detach the process from its parent (the shell). So, when the parent process will be terminated, the child (Irssi) will be able to continue. For this, we use the disown builtin:
$ disown irssi
Launch a screen session:
$ screen
As we are in a screen session, we will retrieve the irssi process. To do so, we use the reptyr command which take a pid:
$ reptyr
To avoid the tedious pid research, we can use the pgrep command:
$ reptyr $(pgrep irssi)
Now the process is in a screen shell, we can safely detach our session and no longer worry about killing our X server or close our ssh connection.
You'll need reptyr for this.
OPTION 2:
I suspect you may be trying to solve the wrong problem. If your SSH connection is dropping, why not address that? You can set SSH to be incredibly tolerant of timeouts and disconnects by tweaking your connection settings.
On your client, in $HOME/.ssh/config add:
ServerAliveInterval 60
ServerAliveCountMax 5
Now your sessions won't timeout even if the server doesn't respond for 5 minutes.
Use ssh-tmux instead of tmux:
function ssh-tmux(){
if ! command -v autossh &> /dev/null; then echo "Install autossh"; fi
autossh -M 0 $* -t 'byobu || {echo "Install byobu-tmux on server..."} && bash'
}
I worked on a text file using nano and I got disconnected. After I logged in I saw the nano process from the previous session was still running, but I couldn't switch to that nano instance. So, I killed the nano process and then it created file named filename.save. Which had my changes from the first session.

Resources