This is Gentoo's testing wiki. It is a non-operational environment and its textual content is outdated.
Please visit our production wiki at https://wiki.gentoo.org
Tmux
Warning: Display title "tmux/zh-cn" overrides earlier display title "Tmux".
tmux (terminal multiplexer) 是一款终端复用类程序,它允许在单个终端(或窗口)中,管理多个分离的会话,窗口及面板。tmux 可以从屏幕上分离并继续在后台运行,然后重新连接。[1] 熟悉GNU Screen 的用户可能会发现tmux是另一个很好的选择。
安装
USE 标记
USE flags for app-misc/tmux Terminal multiplexer
debug
|
Enable extra debug codepaths, like asserts and extra output. If you want to get meaningful backtraces see https://wiki.gentoo.org/wiki/Project:Quality_Assurance/Backtraces |
selinux
|
!!internal use only!! Security Enhanced Linux support, this must be set by the selinux profile or breakage will occur |
systemd
|
Enable use of systemd-specific libraries and features like socket activation or session tracking |
utempter
|
Include libutempter support |
vim-syntax
|
Pulls in related vim syntax scripts |
Emerge
安装 app-misc/tmux:
root #
emerge --ask app-misc/tmux
配置
标准方式安装tmux不会安装全局(/etc/tmux.conf)或用户(~/.tmux.conf)配置文件。示例在 {{Path|/usr/share/doc/tmux-{VERSION}/example_tmux.conf}} 文件中提供,可以复制到全局位置或用户位置,并使用文本编辑器根据需要进行编辑。
程序包示例
要查看配置文件列表,请运行以下命令:
user $
ls /usr/share/doc/tmux-2.0/examples
h-boetes.conf.bz2 n-marriott.conf.bz2 screen-keys.conf.bz2 t-williams.conf.bz2 vim-keys.conf.bz2
然后使用cp将其中一个文件移动到全局位置(将影响所有用户)或用户的主目录下。
Wiki 示例
以下是文件~/.tmux.conf的示例:
set -g default-terminal "screen-256color" # Use 256 colors set -g history-limit 100000 # Scrollback buffer number of lines # Start window indexing at one instead of zero set -g base-index 1 # Set the prefix key and some key bindings to match GNU Screen set -g prefix C-a bind-key C-a last-window # Key bindings for horizontal and vertical panes unbind % bind | split-window -h bind - split-window -v # Enable window titles #set -g set-titles on # Window title string (uses statusbar variables) set -g set-titles-string '#T' # Status bar with load and time set -g status-bg '#4e4e4e' set -g status-fg '#ffffff' set -g status-left ' ' set -g status-right '#[bg=#bbbbbb]#[fg=#000000]#(cut -d " " -f -3 /proc/loadavg) #[bg=#4e4e4e]#[fg=#ffffff]#( date +" %H:%M ")' set -g window-status-format '#I #W' set -g window-status-current-format ' #I #W ' setw -g window-status-current-bg '#55ff55' setw -g window-status-current-fg '#000000' # Pane border colors set -g pane-active-border-fg '#bbbbbb' set -g pane-border-fg '#555555' # Bind to reload config bind r source-file ~/.tmux.conf
插件
A few plugins are available for tmux. See the sections below for available options.
tmux-mem-cpu-load
tmux-mem-cpu-load is a small program designed to monitor system activity in the status line of tmux. See the tmux-mem-cpu-load sub-article for more details on the installation process.
Tmux Resurrect
tmux-resurrect persists tmux environments across system restarts. See the resurrect sub-article for more details on the installation process.
使用
Key bindings
tmux can be controlled from an attached client by using a key combination of a prefix key stroke (Ctrl+b by default) followed by a command key.
After pressing Ctrl+B the following key combinations can be used:
General
- ? = List all key bindings.
- d = Detach the current client.
- : = Enter the tmux command prompt.
Creating and managing windows
- c = Create a new window
- n = Change to the next window.
- p = Change to the previous window.
- l = Move to the previously selected window.
- 0-9 = Select windows 0 to 9.
- ' = Prompt for a window index to select. Then enter a number or title to switch to that window.
- , = Rename the current window.
- w = Choose the current window interactively.
- :, then type list-windows enter = Display the list of windows.
Creating and managing panes
- " = Split the current pane into two, top and bottom.
- % = Split the current pane into two, left and right.
- o = Select the next pane in the current window.
- ; = Move to the previously active pane.
- { = Swap the current pane with the previous pane.
- } = Swap the current pane with the next pane.
- Ctrl+o = Rotate the panes in the current window forwards.
- Alt+1 to Alt+5 = Arrange panes in one of the five preset layouts: even-horizontal, even-vertical, main-horizontal, main-vertical, or tiled.
- x = Kill the current pane.
- ! = Break the current pane out of the window.
Copy, paste, and scroll operations
The keys available depend on whether emacs (default) or vi mode is selected. The mode-keys option can be set in .tmux.conf for vi mode.
- [ = Enter copy mode to copy text or view the history.
- ] = Paste the most recently copied buffer of text.
- # = List all paste buffers.
- - = Delete the most recently copied buffer of text.
Session control
Start session
Once started tmux creates a socket for the session in /tmp/S-<UID>/<Session Name>
tmux can be started with the following command:
user $
tmux
Or, to give the session a name on start up, run:
user $
tmux new-session -s portage
Listing sessions
List tmux sessions to see existing session information:
user $
tmux ls
0: 1 windows (created Thu Apr 9 09:09:03 2015) [180x65] (attached)
When listing sessions the name of the session should appear as the first item in the session information line. It is possible to see from the output above the session was created without a name, hence the session is to be referenced as 0
.
Another way to list sessions is by typing out the long list-sessions
argument.
user $
tmux list-sessions
0: 1 windows (created Thu Apr 9 09:09:03 2015) [180x65] (attached)
The exact same output as the previous list command is displayed.
Renaming a session
Simply using tmux to start a session will not provide the session with a nice, human readable name.
If the default session name is not descriptive enough (0
does not tend to describe much), then a session can be renamed. Suppose Larry the cow started tmux without specifying a session name on start up. He begins working on compiling a new version of Portage, and wants to change the session name to reflect his current task. To change the session name he would first assume control of tmux by pressing the magic key stroke: Ctrl+b, then : which will drop focus into the tmux control line. By default the line should turn yellow. Once there he would issue:
:
rename-session -t 0 portage
Where 0
is the existing (default) session name and portage
is the desired new name for the session. To rename when detached from a tmux session issue:
user $
tmux rename-session -t 0 portage
Resuming a session
After the session is detached, all the active terminals remain active and so do commands that did not finish yet. To resume a session use attach -t <session_name>
.
user $
tmux a -t portage
Or use the long way of attaching to an existing session:
user $
tmux attach -t portage
Daemon-like operation
To start a command in a tmux session without attaching to the session (like a daemon) use new-session -d
followed by the command to execute in quotes:
user $
tmux new-session -d 'emerge -uDNvp @world'
另请参阅
- Screen - An alternative to tmux.
外部资源
- An excellent tmux primer.
- The Tao of tmux, ebook by Tony Narlock, creator of libtmux and tmuxp.