iTerm2增强SSH体验实战

使用了许久的iTerm2,然而只是用了一个tab功能而已,直到某次不小心按了command+D.. So,折腾开始

修改配色

最新版iTerm2(v3.1.5)预置了两个solarized和tango,个人比较喜欢tango-dark。这里有更多的主题可供选择。

增强功能

如果SSH登录到服务器,这部分需要在远端配置一遍。

oh-my-zsh

官方解释是

A delightful community-driven (with 1500+ contributors) framework for managing your zsh configuration. Includes 200+ optional plugins (rails, git, OSX, hub, capistrano, brew, ant, php, python, etc), over 140 themes to spice up your morning, and an auto-update tool so that makes it easy to keep up with the latest updates from the community. https://ohmyz.sh/

一个有众多contributor参与的管理zsh配置的框架,包含200+可选插件 (rails, git, OSX, hub, capistrano, brew, ant, php, python, etc)以及140+满足各种口味的主题。

看来重点是玩插件。根据教程设置了agnoster主题

复制到剪切板

本地可以直接(content) | pbcopy,远程借助remote-pbcopy-iterm2

1
2
ssh (remote addr)
wget -qO- https://github.com/skaji/remote-pbcopy-iterm2/releases/latest/download/pbcopy-linux-amd64.tar.gz | tar xvz - -C ~/.local/bin pbcopy

iTerm2 选中Applications in terminal may access clipboard

然后远程也可以像本地一样输出到剪切板了。

防止断开连接

在客户端增加配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
vim ~/.ssh/config
## ~/.ssh/config begin
Host *
SendEnv LANG LC_*

# macOS Mojave 需要设置为 no 否则照样会断开
TCPKeepAlive no

# 客户端每隔 60S 发送一个空报文
ServerAliveInterval 60

# macOS Mojave 需要增加,原因在于Qos检测命令不被对端支持,导致连接丢失
# packet_write_wait: Connection to 10.10.10.111 port 22: Broken pipe
IPQoS lowdelay throughput
## ~/.ssh/config end

其他

  • 语法高亮插件zsh-syntax-highlighting
  • 命令补全插件zsh-autosuggestions

参考链接

Mac终端配置,DIY你的Terminal (iTerm 2 + Oh My Zsh)

解决macOS Mojave(10.14.6) SSH连接断开问题