将较小的显示器切换到较大的显示器时,有什么方法可以重绘 tmux 窗口吗?

发布于 2024-12-10 15:44:37 字数 173 浏览 0 评论 0原文

我在一个较小的终端上启动了 tmux 会话。当我“附加”到更高分辨率的显示器上的同一会话时,它会在控制台周围绘制点。它不适合新的窗口尺寸。有什么方法可以重绘和清理窗口吗? CTRL+LCTRL-B + R 没有帮助。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

猫卆 2024-12-17 15:44:38

我使用 Ctrl-b + q 这使得每个窗格的闪烁编号,并在途中重新绘制它们。

I use Ctrl-b + q which makes it flash number for each pane, redrawing them on the way.

就此别过 2024-12-17 15:44:37

tmux 将窗口的尺寸限制为该窗口所附加的所有会话中每个尺寸的最小值。如果不这样做,就没有明智的方法来为所有连接的客户端显示整个窗口区域。

最简单的方法是在附加时将任何其他客户端与会话分离:

tmux attach -d

或者,您可以在附加到会话之前将任何其他客户端移动到不同的会话:

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

如果较小的客户端切换到会话,屏幕将再次缩小。

还有一种变体,您只“接管”窗口(将窗口链接到新会话,设置aggressive-resize,并将该窗口处于活动状态的任何其他会话切换到其他窗口) ,但在一般情况下编写脚本比较困难(与“退出”不同,因为您想要取消链接窗口或终止会话,而不是仅仅从会话中分离)。

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).

柠檬色的秋千 2024-12-17 15:44:37

您可以随时按 CTRL-B + SHIFT-D 选择要从会话中分离的客户端。

tmux 将列出所有会话及其当前维度。然后,您只需脱离所有较小规模的会话即可。

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.

陈独秀 2024-12-17 15:44:37

您现在可以在最新版本的 tmux(在 1.9 上测试)上使用一种更简单的解决方案:

tmux detach -a

-a 适用于此会话中除当前客户端之外的所有其他客户端

您可以在 .[bash|zsh 中为它起别名]rc

alias takeover="tmux detach -a"

工作流程:您可以正常连接到您的会话,如果您被另一个强制缩小 tmux 窗口大小的会话打扰,您可以简单地调用 takeover

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.

沩ん囻菔务 2024-12-17 15:44:37

这仍然是搜索时的置顶帖子,但不再有效。 最佳答案在这里,但TLDR是

:resize-window -A

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

燃情 2024-12-17 15:44:37

您可以使用 : + at -d 重绘 tmux窗户。

You can use <Ctrl-B> : + at -d <CR> to redraw the tmux window.

嘿咻 2024-12-17 15:44:37

其他答案对我没有帮助,因为我只附加了客户端(启动会话的上一个答案已经分离)。

为了解决这个问题,我遵循了此处的答案(我没有使用xterm )。

简单地说:

  1. 从 tmux 会话分离
  2. 运行 resize linux 命令
  3. 重新附加到 tmux 会话

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:

  1. Detach from tmux session
  2. Run resize linux command
  3. Reattach to tmux session
世界等同你 2024-12-17 15:44:37

我刚刚遇到这个问题并偶然发现了不同的情况。虽然它可能只是一只独角兽,但我想我应该把它摆出来。

我有一个较小的会话,我注意到字体大小不同:较小的会话具有较小的字体。显然,由于某种原因我改变了窗口字体大小。

因此,在 OS X 中,我只需在较小的会话上执行 Cmd-+ 操作,它就会恢复原状。

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.

Oo萌小芽oO 2024-12-17 15:44:37

可能是一个奇怪的边缘情况,但对我来说,解决它的唯一方法是取消最大化窗口,然后再次最大化它。

Probably an strange edge case but for me the only thing that fixed it was unmaximizing the window and then maximizing it again.

一指流沙 2024-12-17 15:44:37
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

杀死另一个。

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.

束缚m 2024-12-17 15:44:37

由于使用 iTerm 的 tmux 集成(即 tmux -CC a),我遇到了同样的问题。
其他答案中提到的分离选项都不适合我,因为没有“其他会话”可以分离。

我的理解是 iTerm 的 tmux 客户端似乎在附加会话上硬设置了窗口大小,因此后续附加似乎尊重之前调整大小的窗口大小。
唉,我最终通过 tmux -CC a 重新将 iTerm 客户端连接到 tmux,并在 GUI 中手动调整到完整窗口大小(不喜欢在这里使用鼠标,但不幸的是,这最终起作用了)。从 iTerm 中完全分离,后续附加遵循 iTerm 中设置的大小。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文