tmux's zoom (< prefix> + z
or resize-pane -Z) is a toggle.
How do I zoom out (restore) only if the current pane is already zoomed in?
How do I zoom in (maximize) only if the current pane is un-zoomed?
tmux-zoom-in.sh
#!/bin/bash
# Zoom in the current pane ONLY if it is not currently zoomed.
# Requires tmux version >= 1.8
tmux list-panes -F '#F' | grep -q Z || tmux resize-pane -Z
exit 0
tmux-zoom-out.sh
#!/bin/bash
# Zoom out the current pane ONLY if it is not currently zoomed.
# Requires tmux version >= 1.8
tmux list-panes -F '#F' | grep -q Z && tmux resize-pane -Z
exit 0
Related
I'm setting up a window template script in the tmux.conf file and want to have a statement that add a pane title.
In a related post 2019 the solution is partially provided by adding a pane title from the command line - link. A solution is quoted below:-
tmux select-pane -t {pane} -T {title}
Examples:
tmux select-pane -T title1 # Change title of current pane
tmux select-pane -t 1 -T title2 # Change title of pane 1 in current window
tmux select-pane -t 2.1 -T title3 # Change title of pane 1 in window 2`
How do I translate this into a line in the .tmux.conf file?
I've tried the following;
send-keys 'tmux select-pane -t 1 -T titles' C-m ;
select-pane -t 1 -T titles C-m ;
select-pane -t 1-T titles
Finally - although changes to the config file seem to be effected by the continuum & reurrect plugins I found that in order for this to work:-
select-pane -T title1 # Change title of current pane
select-pane -t 1 -T title2 # Change title of pane 1 in current window
select-pane -t 2.1 -T title3 # Change title of pane 1 in window 2
You had to first add the following to the conf file:-
set -g pane-border-format "#{pane_index} #{pane_current_command}"
When I use leader_key + w all the windows from all the session shows up.
Is there an easy way to show and select windows from the current session only ?
I added to my tmux config a custom command (binded to leader_key + a) to show the active windows. This is what I have in my ~/.tmux.conf:
bind-key a resize-pane -Z \; choose-tree "resize-pane -Z \; select-window -t '%%'"
the end result is a view off all the open window in the current session with the option to select one:
(0) - 0: 3 windows (attached)
(1) ├─> 1: less* (1 panes) "pi#raspberry: ~"
(2) ├─> 2: bash (1 panes)
(3) └─> - 3: MachineLearning- (2 panes)
(4) ├─> 1: octave-gui
(5) └─> 2: vim
Tmux is excellent, but there is one quirk that is proving to be a pane. If I hit ctrl+b then go too fast to the arrow key in order to switch panes I end up just resizing the current pane. It would be very nice to get rid of that behaviour. Is this a problem solvable in tmux or is in some kind of lag in my OS?
tmux is fully configurable so, yes, it's possible to solve this issue.
I suggest that you take a look at the tmux man pages or at other resources like Pragmatic Bookshelf's "tmux 2" book.
As an example, you can fully remap the keys to use to split, move around and resize windows adding something like this to your ~/.tmux.conf file:
# Splitting panes
bind | split-window -h # Uses "|" to split pane horizontally
bind - split-window -v # Uses "-" to split pane vertically
# Remapping movement keys
bind h select-pane -L # Move focus to pane on the left
bind j select-pane -D # Move focus to pane above the current one
bind k select-pane -U # Move focus to pane below the current one
bind l select-pane -R # Move focus to pane on the right
bind -r C-h select-window -t :- # Move to previous window
bind -r C-l select-window -t :+ # Move to next window
# Resizing panes (notes that is using the uppercase here and resize by 5 chars)
bind -r H resize-pane -L 5
bind -r J resize-pane -D 5
bind -r K resize-pane -U 5
bind -r L resize-pane -R 5
If I'm working in a widescreen monitor I like to primarily use two panes and switch between them with C-a Ca.
If I'm working on a square monitor I'll use two windows. I'd like to be able to switch between them with C-a C-a as well without changing my tmux.conf.
If you always want C-a to
switch between panes when the active window has more than one pane, and
switch between windows when the active window has only one pane,
then you can use an if-shell that counts the number of panes in the active window to decide between last-pane and last-window:
bind-key C-a if-shell 'test $(tmux list-panes | wc -l) -gt 1' 'last-pane' 'last-window'
It will still be “up to you” to rearrange your panes when switching between “wide” and “square” configurations (e.g. via break-pane and join-pane).
In tmux 1.8 if-shell and run-shell do format expansion, so you can simply the shell command a bit:
bind-key C-a if-shell 'test #{window_panes} -gt 1' 'last-pane' 'last-window'
I'd like to suggest the following (adjust 80 to distinguish between your two terminal widths)
if-shell '[ "$COLUMNS" -gt 80 ]' 'bind-key C-a "select-window -t :.+"' 'bind-key C-a "next-window"'
but I'm either messing up the syntax, or COLUMNS isn't set in the relevant tmux environment, as the above shell expression always evaluates false for me.
I wonder if I can configure a pane in tmux to appear in all windows.
Any hints how to do that?
Of course this is possible, but you would need to run tmux inside a tmux pane.
+-------------+-------------+
| tmux pane 1 | tmux pane 2 |
| | |
| |+-----------+|
| || new tmux ||
| || session ||
| |+-----------+|
+-------------+-------------+
How to do it:
start new tmux session
split pane
unset TMUX in pane 2 # this allows tmux in tmux
start new tmux session in pane
repeat 1-3
run tmux attach -t <target-session> # this is opens the shared session
This does not work as easily if you are running wrappers for tmux, such as come with oh-my-zsh or tmuxinator. And there are probably many reasons you shouldn't do it, I just don't know any of them.
Here's a way to do this, but the mirrored panes will be read-only. There's the pipe-pane command which sends the pane's output to a command. You can have that command write the output to a file and then from the panes you want to mirror from, you can tail -f that file. Example:
# In source pane
tmux pipe-pane 'cat > /tmp/asdf'
# In the target pane (or another tmux session or terminal window)
tail -f /tmp/asdf
no you can't configure a pane to be linked to every window in a traditional sense but you can use tmux's link-window functionality to achieve much of this effect. wrap it in a script or tmux session file to link it to many windows at once.
**edit
you will also want to use the join-pane feature.