minicom output disappears inside tmux on choose-tree - tmux

If minicom is started inside tmux; and the tmux pane with minicom is active then:
if I switch client by 'switch-client -l' - minicom output is ok;
but if by 'choose-tree -NZs' - minicom output disappears like by minicom command 'ctrl-a, c' ("Clears the screen" from the man page);
If another tmux pane or window is active - minicom output is ok.
Any solution to keep minicom output in all cases?
tmux 2.7 inside Konsole Version 17.12.3
OpenSuse Leap 15.0, kernel 4.12.14

The reason is '-Z' argument in 'choose-tree -NZs' command. By this argument, the pane zooms what brings to clearing screen. Replacing the command by 'choose-tree -Ns' solves the problem.

Related

How to make the middle mouse button paste from the primary selection in tmux when mouse mode is enabled?

In most terminal emulators Middle Mouse Button will paste from the X Windows primary selection. In tmux with mouse mode enabled (set -g mouse on) Middle Mouse Button no longer pastes from the primary selection because the mouse click is captured by tmux rather than by the terminal emulator. To paste you have to do Shift + Middle Mouse Button to pass the click through to the terminal emulator.
How can I make Middle Mouse Button paste without having to hold down Shift, even when mouse mode is enabled?
In tmux 3.2, this change was made.
CHANGES FROM 3.1c TO 3.2
Add a default binding for button 2 to paste.
Add this to your ~/.tmux.conf file:
# Make middle-mouse-click paste from the primary selection (without having to hold down Shift).
bind-key -n MouseDown2Pane run "tmux set-buffer -b primary_selection \"$(xsel -o)\"; tmux paste-buffer -b primary_selection; tmux delete-buffer -b primary_selection"
Requires xsel to be installed. (sudo apt install xsel on Ubuntu.)
Explanation
Adds a Middle Mouse Button (MouseDown2Pane) binding that:
Uses tmux set-buffer to load the output of the xsel -o command (i.e. the contents of the primary selection) into a temporary tmux paste buffer named primary_selection
Uses tmux paste-buffer to paste the primary_selection buffer into the current pane
Uses tmux delete-buffer to delete the primary_selection buffer. This is to avoid messing with your buffers. tmux's paste command (Ctrl + b ] by default) pastes from the most-recently-created paste buffer. We don't want the primary_selection buffer to become your most-recently-created buffer and replace the previous buffer for the Ctrl + b ] binding. Nor do we want the primary_selection buffer to appear in your buffers list. So we delete it

tmux split-window without changing focus

Is there any way to split a window in tmux without changing the current focus?
I'm running a script inside one of my tmux panes that occasionally runs "tmux split-window ..." with some command that takes a minute to complete and MAY request input.
I can end up trying to type input into one of the tmux panes but in the middle of my typing, the original pane executes "tmux split-window ..." and (mid word) my cursor shifts to the new pane, and I end up typing part of the input into the wrong pane.
Note: this answer is correct, but obsolete. The right way is to use -d flag for split-window command. I'm leaving this answer as a demonstration how to do some yak shaving with tmux.
A split-window command flag provided by tmux would be the right solution for this. Unfortunately tmux does not provide such command flag. Update: there is a -d split-window flag that does this.
The simple solution is to immediately switch to previous pane after split-window:
tmux split-window
tmux last-pane
This can be also written as a one liner:
tmux split-window\; last-pane
The downside of this solution is that *theoretically* you might end up writing a character in the wrong window if you type it in time interval between split-window and last-pane command execution.
Here another approach with the downside that it's more complex.
Create a new window in the background and get the pane_id of this window (note how this command is wrapped in $(...) because we want it executed in a subprocess:
pane_id=$(tmux new-window -d -P -F "#{pane_id}")
Now join the window we just created with the window where your cursor is located (will not change cursor focus):
tmux join-pane -b -t "$pane_id"
Add -h to the join-pane above if you want a horizontal split.
I recommend taking the first approach for it's simplicity. It's highly unlikely you'll have any practical issues with it.

Set/Unset bell/flag state for a window

I tend to have multiple windows in a tmux session, and run long processes (such as database migrations and complex queries, etc) in one window while I keep focus on another.
I'd like to set something up to flag the window when the process is finished. I plan to do this with zsh functions, but I'm having trouble finding the command to set a bell on a given tmux window. I looked at set-window-option and I found window_flag but I don't know how to set window_flag
How can I set and clear an indicator for a given tmux window via a shell command?
In order to send a bell to any terminal, including tmux, you just have to print \a to the terminal. You can use echo '\a' or print '\a' for that. (On shells other than ZSH you might need to use echo -e '\a' or printf '\a' instead.)
If a bell occurred in a window tmux adds a ! to the window name in the status bar. Activating a window automatically removes the bell flag, that also means that a the flag will not be set if the bell occurs in the currently active window.
You can also set a separate style for these windows in the status line with window-status-bell-style option (the default seems to be reverse, that is switching fore- and background colors).
Additionally you can get tmux to show a short message if a bell occurred by setting the bell-action option to any.
I have the following in my ~/.zshrc to ring the bell, if a process takes at least 60 seconds to finish:
autoload -Uz add-zsh-hook
typeset -i LONGRUNTIME=60
save_starttime () {
starttime=$SECONDS
}
set_longrunning_alert () {
if ((LONGRUNTIME > 0 && SECONDS - starttime >= LONGRUNTIME)); then
print "\a"
fi
}
add-zsh-hook preexec save_starttime
add-zsh-hook precmd set_longrunning_alert

tmux maximize/minimize pane bug -- "Session not found: tmp"

description of what's happening:
when minimizing a maximized pane, this message appears at bottom of terminal window: "Session not found: tmp"
pane appears to return to same place as initial/previous session
but the new tmp window (that was opened when the pane was first maximized) fails to close and appears in the list of windows (in the status bar at the bottom of tmux)
my hunch is kill-window -t tmp (in the below .tmux.conf code) is where things break. since executing a command in the tmp window appears to rename the window, kill-window -t tmp won't work.
so my question is: how could i alter .tmux.conf to prevent this from happening?
steps to recreate bug:
(note: you would need to have modified .tmux.conf for these commands to work)
start tmux and create session w/ at least two panes
maximize one pane using [prefix] + [up]
execute a shell command in maximized pane (*)
minimize pane using [prefix] + [down]
(*) if pane is maximized and minimized w/out executing a command in the shell this problem does not appear to occur. i.e. if you're editing a file in a pane, then maximize that pane, and only edit/save the file (w/out exiting and then executing another command), then minimize -- the bug doesn't occur.
30s youtube clip showing what happens: http://youtu.be/WMdOeJdOYuU
code that might be causing the error (from ~/.tmux.conf):
unbind Up
bind Up new-window -d -n tmp \; swap-pane -s tmp.0 \; select-window -t tmp
unbind Down
bind Down last-window \; swap-pane -s tmp.0 \; kill-window -t tmp
[edit: HERE IS THE SOLUTION]
thanks to a helpful #tmux irc'er (who has this link and whom i will happily give credit) this question is solved. i don't yet have enough cred to answer this question so i'm posting the solution here.
the solution is to add set-window-option -g allow-rename off to ~/.tmux.conf
this works b/c tmp doesn't get renamed so kill-window -t tmp can properly execute.
(thx for the help and feel free to answer this so i can give you credit!)
You want allow-rename set to off, at least for that one window:
set-window-option -g allow-rename off

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