iTerm2 使用笔记

iTerm2 使用了1年多了,一些功能其实还没有主动去发现,这次接着项目忙完的空闲时间整理一下tips,提高工作效率,方便以后查阅。

一、几个术语

从小到大:session > pane > tab > window

image.png

二、好用的功能

1、Toggle Broadcasting Input - 广播输入

session窗口右键 > Toggle Broadcasting Input

(1)当多个session一起打开,将同步输入
(2)更多设置(shell > Toggle Broadcasting Input

image.png

2、多窗口(panes)

shell 下:
image.png

(1)shell > Duplicate Tab 可以快速新建一个 tab 且保留上一个 tab 的 pane 样式

3、清空 session 内容

(1)edit > Clear Buffer —— 清空所有

(2)edit > Clear Scrollback Buffe —— 清空除了当前的所有

4、恢复不小心关掉的窗口

Edit > Undo Close Session

(1)只支持恢复几分钟前不小心关闭的(原理是赶在没有真正断开链接前)

5、copy mode —— 复制模式

专门切换到用于复制的模式,此模式下不能修改任何内容

Edit > Copy Mode

基本操作:

(1)空格toggle到复制光标状态
(2)上下左右剪头移动复制光标
(3)更多高级操作请看文档:https://www.iterm2.com/documentation-copymode.html

6、关于历史时间

(1)显示命令执行的时间 View > Show Timestamps`

(2)时光倒流 View > Show Annotations`

image.png

7、给不同的 window 上颜色

View > Tab Color ,用来区分不同窗口的功用。

8、侧边栏工具箱

Toolbelt 下可以打开不同的工具窗口:

image.png

我常用的是两个:

image.png

可以用下面实现相同的效果:

Session > Open Command History..
Session > Open Recent Directories...

9、隐藏 / 恢复 session

(1)隐藏 session:

session窗口右键 > BurySession > Bury Session

(2)恢复 session:

Session > Buried Sessions

10、多window自动布局

开的 window 太多,可以用 Window > Arrange Windows Horizontally 自动布局

11、列出所有 window 并支持搜索

Window > Expose all Tabs

12、无鼠标复制

在搜索框按tab,可以拓展选择匹配结果后面的单词

image.png

三、与 Shell 集成

新版本的 iTerm2 可以与unix shell(支持tcsh、zsh、bash、fish 2.3)集成,提供更多功能。

1、安装

因为我用的是 zsh,所以不要用 iTerm2 > Install Shell Integration,而是执行:

curl -L https://iterm2.com/shell_integration/zsh \ 
-o~ / .iterm2_shell_integration.zsh

# 然后将下面添加到〜/ .zshrc的末尾:
source~ / .iterm2_shell_integration.zsh

2、Marks and Annotations —— 标记与备注

(1)添加 Mark(标记):

与 Shell 集成后,所有的命令行都会被自动标记为mark。

没有跟与 Shell 集成前,可以通过Marks and Annotations > Set Mark在最近的命令行添加 Mark。

(2)添加 Annotation(备注):

在最近的命令行添加 Annotation:Marks and Annotations > Add Annotation at Cursor
任意地方添加 Annotations:session窗口右键 > Annotate Selection

(3) 移动位置(包括 mark 和 Annotation)

快捷键:Cmd+Shift+上/下剪头

跳到上一个mark / Annotation:Marks and Annotations > Previous Mark/Annotation
跳到下一个mark / Annotation:Marks and Annotations > Next Mark/Annotation

若跳到 mark,会有颜色提示,蓝色表示成功的命令,红色表示失败的命令

跳到最近的 Mark:Marks and Annotations > Jump to Mark

(4) 显示所有 Annotation

View > Show Annotations

3、命令执行完后提醒

(1)弹窗方式:Edit > Marks and Annotations > alerts > Show Modal Alert Box
(2)提醒栏方式:Edit > Marks and Annotations > alerts > Post Notification

4、查看历史命令状态

在命令(mark 过的)的三角形处右击:

image.png

四、更多特性

看官方文档:https://www.iterm2.com/features.html

五、DIY 功能

1、实现双击 Profiles 的服务器可以免密登录

(1)Profiles 设置里,指定如下图的路径expect /Users/xjnotxj/Program/ssh/121.xxx.xxx.xxx

image.png

(2)路径指定的文件121.xxx.xxx.xxx,内容如下:


#!/usr/bin/expect -f  
  set user root  
  set host 121.xxx.xxx.xxx
  set password xxxxsxx
  set timeout -1  
   
  spawn ssh $user@$host -o StrictHostKeyChecking=no 
  expect "*assword:*"  
  send "$password\r"  
  interact  
  expect eof  

猜你喜欢

转载自www.cnblogs.com/xjnotxj/p/10272591.html
今日推荐