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  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM