What is the bottom left number in tmux status bar? - terminal

Cannot figure it out what is the [3] number.

That is the Tmux session name. You can rename it using:
CTRL + B, $
or
CTRL + B, :
To list the sessions, do CTRL + B, : and write ls or CTRL + B, s.
By default, the session number is displayed.

It's the tmux session name.
That indicates you have three tmux sessions opened.
You can attach a terminal to a session using:
tmux attach
Edit
Active sessions can be discovered using:
tmux list-sessions
To close propperly a session:
tmux kill-session <session_name>

Related

bind source-file in tmux on startup from bash

I have a .tmux.conf file which binds a set of further tmux instructions when I press the correct keys (in this case, Ctrl + b followed by 'k'):
bind k source-file ~/.tmux/myfile
When I go into my tmux terminal and press Ctrl + b followed by k, it works fine, and the script in myfile runs as expected. I'm now trying to launch this all using a command in my .bashrc file by sending the keys to the tmux session once it has launched:
launch_things() {
tmux new-session -d -s mysession
tmux send-keys -t mysession C-b k
tmux a -t mysession
}
However, this doesn't work. It's starting the tmux session, apparently benting the keys to it, then attaching to the session. I'm not sure if it's because I've done something wrong with the sending of the keys, or if it's not possible to send combinations of keys like this. Note that I can see the letter k on the screen when I attach, so the send-keys functionality is doing something.
Can anyone either tell me what I'm doing wrong, or suggest another way to launch my bound source-file (~/.tmux/myfile) from my bash script please?
P.S. I'm running Ubuntu 16.04 if that makes a difference.
It seems that send-keys when sending strings does not try to interpret them for the prefix character. There is the command send-prefix but that behaves in the same way.
So the simple answer is to do tmux source-file ~/.tmux/myfile or perhaps the longer
tmux attach-session -t mysession\; source-file ~/.tmux/myfile\; detach-client

how to scroll to beginning/end of scroll buffer in tmux?

^b+page up/down scrolls up/down one page of scroll buffer, but how do we scroll to beginning ?
like wise with end (besides pressing ^C to kill scrolling)
this depends on the binding of "mode-keys". If you "set-option -g mode-keys emacs" (actually, this is the default settings), then you can go to the beginning and the end of the buffer using corresponding emacs keys.
Enter the copy mode using: ctrl-b + [
Go to the beginning using: Alt + shift + , (or, in emacs' notation: M-<)
Similarly, going to the end is achieved by M->
HOW TO TEST
Please note that configuration in ~/.tmux.conf only takes effect after the tmux server restarts. That is when you kill all sessions and then restart tmux.
In fact, however, there is simpler way to test: just run the following command at command line:
tmux set-option -g mode-keys emacs
I don't think there is a way change only one key. But you do have the choice to
tmux set-option -g mode-keys vi
You should be able move around in copy mode using h j k l etc.
You can use like:
bind-key -T copy-mode C-S-Home send -X history-top # Ctrl+Shift+Home
bind-key -T copy-mode C-S-End send -X history-bottom # Ctrl+Shift+End
This way when you are in copy mode Ctrl+Shift+Home will take you to the beginning of scroll buffer and Ctrl+Shift+End will take you to the end of scroll buffer.

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.

Graceful way of closing a broken SSH pipe on OSX?

I've heard that the shift + tilda + period is supposed to close a hanging ssh pipe, but I can not simply ever get it to work. So my question to stackoverflow is, how do I gracefully close a broken SSH pipe on OSX?
When I type <enter> ~ . I leave the ssh session. This is on a German keyboard where I have to type <alt>+n <space> (where <alt>+n means to press n while holding down the alt key) to get a tilde. So the key sequence is for me: <enter> <alt>+n <space> ..

How to send commands when opening a tmux session inside another tmux session?

A typical situation may be:
$ tmux
[0] $ ssh example.com
$ tmux attach
[0] $
I open a tmux session, then ssh in to a server and attach to an existing tmux session. At this point I have one tmux session inside another. How do I send commands to the inner tmux session?
Note: Both tmux sessions have the same key bindings.
The send-prefix command can be used to send your prefix keystroke to (the process running in) the active pane. By default, the prefix is C-b and C-b is bound to send-prefix (so that hitting it twice sends a single C-b to the active pane). This is just what we need to access the bindings of the inner tmux instance.
The first C-b is captured by the “outer” tmux instance as its prefix key. The second one is captured by the “outer” tmux instance and triggers its C-b binding (send-prefix). This sends a C-b to the outer instance’s active pane. The process running in this pane is (ultimately, through an ssh instance) the “inner” tmux instance. It captures the C-b as its prefix key. Now your next keystroke will be passed through the outer tmux instance and captured by the inner one to trigger a binding.
To trigger the c binding (new-window) in a second-level instance of tmux, you would type C-b C-b c. For a third-level instance of tmux you would type C-b C-b C-b C-b c.
This doubling for each level can be annoying if you are commonly dealing with multiple layers of tmux. If you can spare some other key, you could make a non-prefixed binding to make things (possibly) easier to type:
bind-key -n C-\ send-prefix
bind-key -n C-^ send-prefix \; send-prefix
Create new window in second-level tmux: C-\ c
Create new window in third-level tmux: C-^ c (or C-\ C-\ c)
If you have a limited number of tmux commands that you want to (easily) send to the lower-level tmux instances, you might instead use send-keys to create some specific bindings (possibly just in your top-level tmux instance):
bind-key C-c send-keys C-b c
bind-key C send-keys C-b C-b c
Create new window in second-level tmux: C-b C-c
Create new window in third-level tmux: C-b C
To access the inner, hold control and hit B twice.
EDIT:
I do NOT recommend use C-q as a bind-key, as it is a default control-key command for
un-freezes the screen and lets screen display continue
A situation happens here, and #Paschalis provides a solution:
if it happens to be twice unlucky (a remote tmux session with C-q as prefix): Type Cltr-q, then :, and enter in tmux: send-keys C-q
Below it is the answer:
To make it simple, add the below line in your ~/.tmux.conf
bind-key -n C-q send-prefix
Then you can directly use C-q as bind-key for your remote tmux.

Resources