Accessing different panes inside the same window on separate sessions - tmux

I have iTerm2 running with two horizontal splits, split_A and split_B.
I am attached to the same tmux sessions in split_A and in split_B.
I have one window running in the tmux session, with 2 panes, pane_A and pane_B
When I do next-pane in one of the splits, the tmux running in the other split does exactly the same and moves to the next pane. So the tmux sessions are synced.
Is there a way to display pane_A in one of the tmux sessions and pane_B in the other.
Just to make sure: pane_A and pane_B are running in the same window and same session.
|-----------------------------------|
||---------------------------------||
|| iterm2 split, tmux:windowA:1 ||
||---------------------------------||
|| iterm2 split, tmux:windowA:0 ||
||---------------------------------||
|-----------------------------------|
Just because panes do not have names, so I would like to have the top tmux names console and the bottom files and their session called DEV.
DEV > CONSOLE (top split)
DEV > FILES (bottom split)
Apologies for the horrible ASCII art.

Thinking about the goal of tmux, I believe there is no way to do what your described. In addition, it seems to me that in this case you can go with one iterm window + two tmux panes, simple and easy. Why you split iterm in the first place?

Related

Can the number of sleeping task in the current window be shown in Tmux statusbar?

I often use ^Z to make sleep a process, possibly open a new one, make this one sleep too, and so on, also moving between different Tmux windows.
So what I would like, is that the Tmux status bar update relevantly to indicate me how many processes are sleeping in the currently focused window.
Is that possible?
This is a common question - how to pass information from a shell inside tmux to tmux. The easiest way to do this is to have your shell do it as part of PS1 or some other variable that is evaluated when the prompt is printed.
There are two things you can do:
1) Set a user option with tmux set -w #myoption xyz, then you can use it in the status line with #{#myoption}. This has the disadvantage that it cannot work over ssh.
2) Set the pane title using the escape sequence, for example: printf "\033]2;xyz\033\\". It is then available in #{pane_title}. This works over ssh but had the disadvantage that there is no way to prevent applications also changing the title if they want.
In either case you will only want to run this when TMUX is set, so something like:
[ -n "$TMUX" ] && tmux set -w #myoption $(jobs|wc -l)

Start tmux with specific layout

I have a question and searched on the web but didn't find a specific solution, or solutions didn't work for me.
In order to start tmux with a specific layout of panes, I'd like to setup my tmux.conf accordingly.
Now, I found something like this:
new -s my_sess # create new session
neww -n shell # create new window
splitw -v
Which has no effect, since I see only one window, not split into panes. Another trial was like this:
# Automatically set window title
set-window-option -g automatic-rename on
set-option -g set-titles on
# Split the pane horizontally
splitw -h
Which results in an error no current target.
It's probably a stupid mistake of mine caused by poor understanding. But I hope that people here might be able to help.
I'd say that this very basic task is covered abominably in the available tmux resources.
It cost me six hours of perusing material to come to a solution. The biggest help came from https://gist.github.com/sdondley/b01cc5bb1169c8c83401e438a652b84e
Your minimal .tmux.conf file shall be (you got there 99%):
new -s my_sess # create new session
neww -n shell # create new window
split-window -t shell # split vertically the window just created
and you have to launch it with tmux attach instead of a plain tmux.
I have created a gist to sum up my experiences. It covers also topics like launching different commands in each new pane.
If you create new sessions in .tmux.conf, you probably want to start tmux with tmux attach not tmux new. If you don't, you will be creating both your session in .tmux.conf and a new session, which is probably not what you want. Your first attempt looks OK, so I guess this is what you are doing.
Also remember .tmux.conf is only loaded on server startup, so only the first time you run tmux. If you want to create a new session like this later, put it in a separate config file and load it with source-file.

Tmux keeps changing window

I'm discovering Tmux, and I'm facing an annoying problem:
When i switch window in Tmux with ctrl + arrow, Tmux keeps the focus on my keyboard.
here is an example of what it does: when i do ctrl + B [left arrow] [upper arrow], instead of going to the left window (terminal) and display my previous command, Tmux go to the left window, and then, to the upper window.
Anyone know any way to lose the focus after one command? I did not found any answers atm
Thanks
Add this to your ~/.tmux.conf
# command delay, don't want that, make it short
set -g escape-time 10
# Allow the arrow key to be used immediately after changing windows
set-option -g repeat-time 0

How to change tmux keyboard hotkey to do the two things at once?

How do I accomplish
[press C-a q] -> [me selecting one of the pane indices] -> [C-a z (to zoom)]
with just first two steps?
In other words, I want to rebind C-a q <NUMBER> so that the at the end, the selected pane is automatically zoomed in
I think this solution should work, put the following line in your .tmux.conf:
bind q choose-window "select-window -t '%%'; resize-pane -Z"
Then reload it by executing this command from the shell: tmux source ~/.tmux.conf
Note a couple things:
This has been tested on latest tmux version 1.9a. It might as well work on earlier versions (but I haven't tested).
Selecting a window is interactive! You can either press a <NUMBER> to select a window or use keyboard arrows to choose window.
Zooming feature will *toggle* zoom in the target window! So if the target window is already zoomed, it will get un-zoomed.

Is there any way to redraw tmux window when switching smaller monitor to bigger one?

I started a tmux session on a smaller terminal. When I "attach" to the same session on a larger resolution monitor, it draws dots around the console. It doesn't fit the new window size. Is there any way to redraw and clean the window? CTRL+L or CTRL-B + R doesn't help.
tmux limits the dimensions of a window to the smallest of each dimension across all the sessions to which the window is attached. If it did not do this there would be no sensible way to display the whole window area for all the attached clients.
The easiest thing to do is to detach any other clients from the sessions when you attach:
tmux attach -d
Alternately, you can move any other clients to a different session before attaching to the session:
takeover() {
# create a temporary session that displays the "how to go back" message
tmp='takeover temp session'
if ! tmux has-session -t "$tmp"; then
tmux new-session -d -s "$tmp"
tmux set-option -t "$tmp" set-remain-on-exit on
tmux new-window -kt "$tmp":0 \
'echo "Use Prefix + L (i.e. ^B L) to return to session."'
fi
# switch any clients attached to the target session to the temp session
session="$1"
for client in $(tmux list-clients -t "$session" | cut -f 1 -d :); do
tmux switch-client -c "$client" -t "$tmp"
done
# attach to the target session
tmux attach -t "$session"
}
takeover 'original session' # or the session number if you do not name sessions
The screen will shrink again if a smaller client switches to the session.
There is also a variation where you only "take over" the window (link the window into a new session, set aggressive-resize, and switch any other sessions that have that window active to some other window), but it is harder to script in the general case (and different to “exit” since you would want to unlink the window or kill the session instead of just detaching from the session).
You can always press CTRL-B + SHIFT-D to choose which client you want to detach from the session.
tmux will list all sessions with their current dimension. Then you simply detach from all the smaller sized sessions.
A simpler solution on recent versions of tmux (tested on 1.9) you can now do :
tmux detach -a
-a is for all other client on this session except the current one
You can alias it in your .[bash|zsh]rc
alias takeover="tmux detach -a"
Workflow: You can connect to your session normally, and if you are bothered by another session that forced down your tmux window size you can simply call takeover.
This is still the top post when searching, but it's no longer valid. Best answer is here, but the TLDR is
<c-b>:resize-window -A
You can use <Ctrl-B> : + at -d <CR> to redraw the tmux window.
The other answers did not help me as I only had client attached (the previous one that started the session was already detached).
To fix it I followed the answer here (I was not using xterm).
Which simply said:
Detach from tmux session
Run resize linux command
Reattach to tmux session
I just ran into this problem and stumbled across a different situation. Although it's probably just a unicorn, I thought I'd lay it out.
I had one session that was smaller, and I noticed that the font sizes were different: the smaller session had the smaller fonts. Apparently, I had changed window font sizes for some reason.
So in OS X, I just did Cmd-+ on the smaller sized session, and it snapped back into place.
Probably an strange edge case but for me the only thing that fixed it was unmaximizing the window and then maximizing it again.
ps ax | grep tmux
17685 pts/22 S+ 0:00 tmux a -t 13g2
17920 pts/11 S+ 0:00 tmux a -t 13g2
18065 pts/19 S+ 0:00 grep tmux
kill the other one.
I had the same problem because of using iTerm's tmux integration (i.e., tmux -CC a).
None of the detach options mentioned in the other answers worked for me, because there was no "other sessions" to detach from.
My understanding is iTerm's tmux client seems to hard set the window size on the attached session, so the subsequent attaches seem to respect the previously resized window size.
Alas, I ended up reattaching iTerm client to tmux via tmux -CC a and manually resized to full window size in GUI (not happy using mouse here, but that is what worked in the end, unfortunately). Clean detach from iTerm and subsequent attaches follows the size set in iTerm.
I use Ctrl-b + q which makes it flash number for each pane, redrawing them on the way.

Resources