Recently, when using an open source tool, I found a tool called tmux. Then I found that Tmux is quite popular, the repo star has 20K+, and my commonly used iTerm2 is also integrated with tmux. Based on this, it is necessary to understand tmux and clarify the usage scenarios.
Since the current use is still shallow, please point out if any mistakes
Start with the concept and understand its function.
tmux is a terminal multiplexer. It lets you switch easily between several programs in one terminal, detach them (they keep running in the background) and reattach them to a different terminal.
- Personal understanding is that tmux saves the terminal session on-site. For example, SSH is connected to a VPS, vi edits a file, directly closes the session, and then reopens the connection, you will find that the state is lost, you need to re-enter the target path and reopen it edit. With tmux, you can save this session, re-access the target machine, load the previously saved session, and everything will be restored as before.
- The reason why tmux can save sessions is because after tmux is installed on the target server, a separate service will be started for on-site saving.
Understand the above principles, you can understand that tmux is not necessarily installed locally, but
installed on the machine that needs to save the session.
The installation commands in common operating system environments are as follows
After Tmux is installed, followed by the settings of the local terminal App
- Global tmux settings
The picture shows my current settings, basically keep the default settings.
Individual profile configuration startup command
For the machine where tmux needs to be enabled, the command configuration is as follows.
# Connect to the target machine, then execute the tmux session load, if not, open a new session
ssh -p 22 -t email@example.com "tmux -CC attach || tmux -CC"
It can be used after setting as above.
Searching for information, you will find that tmux is very rich in configuration and can be very complicated to use, which invisibly increases the mental burden, but you don’t need to worry about it.
In the case of using iTerm2, operations such as split screen and session opening are already available. iTerm2 itself has mapped many functions of tmux, so it is enough to maintain the operating habits of iTerm2. After in-depth use, if there are still insufficient Fill in the gaps.