iTerm2 使用筆記

iTerm2 使用了1年多了,一些功能其實尚未主動去發現,此次接着項目忙完的空閒時間整理一下tips,提升工做效率,方便之後查閱。html

1、幾個術語

從小到大:session > pane > tab > windowshell

image.pngbash

2、好用的功能

一、Toggle Broadcasting Input - 廣播輸入

session窗口右鍵 > Toggle Broadcasting Input服務器

(1)當多個session一塊兒打開,將同步輸入 (2)更多設置(shell > Toggle Broadcasting Input )  image.pngsession

二、多窗口(panes)

shell 下: image.pngssh

(1)shell > Duplicate Tab 能夠快速新建一個 tab 且保留上一個 tab 的 pane 樣式curl

三、清空 session 內容

(1)edit > Clear Buffer —— 清空全部工具

(2)edit > Clear Scrollback Buffe —— 清空除了當前的全部佈局

四、恢復不當心關掉的窗口

Edit > Undo Close Sessionurl

(1)只支持恢復幾分鐘前不當心關閉的(原理是趕在沒有真正斷開連接前)

五、copy mode —— 複製模式

專門切換到用於複製的模式,此模式下不能修改任何內容

Edit > Copy Mode

基本操做:

(1)空格toggle到複製光標狀態 (2)上下左右剪頭移動複製光標 (3)更多高級操做請看文檔:https://www.iterm2.com/documentation-copymode.html

六、關於歷史時間

(1)顯示命令執行的時間 View > Show Timestamps`

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

image.png

七、給不一樣的 window 上顏色

View > Tab Color ,用來區分不一樣窗口的功用。

八、側邊欄工具箱

Toolbelt 下能夠打開不一樣的工具窗口:

image.png

我經常使用的是兩個:  image.png

能夠用下面實現相同的效果:

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

九、隱藏 / 恢復 session

(1)隱藏 session:

session窗口右鍵 > BurySession > Bury Session

(2)恢復 session:

Session > Buried Sessions

十、多window自動佈局

開的 window 太多,能夠用 Window > Arrange Windows Horizontally 自動佈局

十一、列出全部 window 並支持搜索

Window > Expose all Tabs

十二、無鼠標複製

在搜索框按tab,能夠拓展選擇匹配結果後面的單詞

image.png

3、與 Shell 集成

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

一、安裝

由於我用的是 zsh,因此不要用 iTerm2 > Install Shell Integration,而是執行:

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

# 而後將下面添加到〜/ .zshrc的末尾:
source~ / .iterm2_shell_integration.zsh

二、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

三、命令執行完後提醒

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

四、查看歷史命令狀態

在命令(mark 過的)的三角形處右擊:

image.png

4、更多特性

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

5、DIY 功能

一、實現雙擊 Profiles 的服務器能夠免密登陸

(1)Profiles 設置裏,指定以下圖的路徑expect /Users/xjnotxj/Program/ssh/121.xxx.xxx.xxximage.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
相關文章
相關標籤/搜索