一、前置條件:
安裝好HomeBrew 和 iTerm2 ,HomeBrew 已經(jīng)支持M1版本了,正常安裝即可。
二、提前準備文件:
1.用記事本新建文件命名為iterm2-recv-zmodem.sh,內(nèi)容如下
#!/bin/bash
# Author: Matt Mastracci (matthew@mastracci.com)
# AppleScript from http://stackoverflow.com/questions/4309087/cancel-button-on-osascript-in-a-bash-script
# licensed under cc-wiki with attribution required
# Remainder of script public domain
osascript -e 'tell application "iTerm2" to version' > /dev/null 2>&1 && NAME=iTerm2 || NAME=iTerm
if [[ $NAME = "iTerm" ]]; then
FILE=`osascript -e 'tell application "iTerm" to activate' -e 'tell application "iTerm" to set thefile to choose folder with prompt "Choose a folder to place received files in"' -e "do shell script (\"echo \"&(quoted form of POSIX path of thefile as Unicode text)&\"\")"`
else
FILE=`osascript -e 'tell application "iTerm2" to activate' -e 'tell application "iTerm2" to set thefile to choose folder with prompt "Choose a folder to place received files in"' -e "do shell script (\"echo \"&(quoted form of POSIX path of thefile as Unicode text)&\"\")"`
fi
if [[ $FILE = "" ]]; then
echo Cancelled.
# Send ZModem cancel
echo -e \\x18\\x18\\x18\\x18\\x18
sleep 1
echo
echo \# Cancelled transfer
else
cd "$FILE"
/usr/local/bin/rz -E -e -b
sleep 1
echo
echo
echo \# Sent \-\> $FILE
fi
2.用記事本新建文件命名為iterm2-send-zmodem.sh,內(nèi)容如下
#!/bin/bash
# Author: Matt Mastracci (matthew@mastracci.com)
# AppleScript from http://stackoverflow.com/questions/4309087/cancel-button-on-osascript-in-a-bash-script
# licensed under cc-wiki with attribution required
# Remainder of script public domain
osascript -e 'tell application "iTerm2" to version' > /dev/null 2>&1 && NAME=iTerm2 || NAME=iTerm
if [[ $NAME = "iTerm" ]]; then
FILE=`osascript -e 'tell application "iTerm" to activate' -e 'tell application "iTerm" to set thefile to choose file with prompt "Choose a file to send"' -e "do shell script (\"echo \"&(quoted form of POSIX path of thefile as Unicode text)&\"\")"`
else
FILE=`osascript -e 'tell application "iTerm2" to activate' -e 'tell application "iTerm2" to set thefile to choose file with prompt "Choose a file to send"' -e "do shell script (\"echo \"&(quoted form of POSIX path of thefile as Unicode text)&\"\")"`
fi
if [[ $FILE = "" ]]; then
echo Cancelled.
# Send ZModem cancel
echo -e \\x18\\x18\\x18\\x18\\x18
sleep 1
echo
echo \# Cancelled transfer
else
/usr/local/bin/sz "$FILE" -e -b
sleep 1
echo
echo \# Received $FILE
fi
三、開始配置
第一步:安裝lrzsz
打開iTerm2 ,輸入 brew install lrzsz 安裝 lrzsz
第二步:放置文件
打開Finder后,按鍵command + shift + g 打開快速前往,輸入/usr/local/bin進入該文件夾下。
將剛才的兩個文件放入該文件夾,需要輸入密碼輸入登錄密碼即可。
第三步:配置文件權(quán)限
打開iTerm2 ,輸入 cd /usr/local/bin 進入該目錄。再輸入chmod 777 iterm2-* 調(diào)整文件權(quán)限為777。
第四步:軟連接執(zhí)行文件(關(guān)鍵)
新版的brew路徑和老版本不同,上面兩個文件寫死了路徑,所以這里使用軟連接將文件指向進行調(diào)整。
在iTerm2 中輸入以下指令:
sudo ln -s /opt/homebrew/bin/rz /usr/local/bin/rz
sudo ln -s /opt/homebrew/bin/sz /usr/local/bin/sz
參考文章
第五步:打開iTerm2中Edit
點擊iTerm2,選擇 Preference... -> Profiles -> Default -> Advanced -> Edit (in Triggers),如圖
第六步:配置Edit中選項

可以看到每一個觸發(fā)器(Trigger)都有幾個選項需要配置。這里我們添加上傳和下載的觸發(fā)器。
其各個選項配置如下:
1.下載觸發(fā)器配置:
1. Regular expression 中填寫
rz waiting to receive.\*\*B0100
2. Action 選擇
Run Silent Coprocess...
3. Parameters 中填寫
/usr/local/bin/iterm2-send-zmodem.sh
4. Instant 不勾選
5. Enabled 勾選
2.上傳觸發(fā)器配置:
1. Regular expression 中填寫
\*\*B00000000000000
2. Action 選擇
Run Silent Coprocess...
3. Parameters 中填寫
/usr/local/bin/iterm2-recv-zmodem.sh
4. Instant 不勾選
5. Enabled 勾選
配置完成如圖:

第七步:使用
在使用登錄服務(wù)器后,到相應(yīng)的地方,輸入rz ,會彈出一個文件選擇器,選擇后開始上傳。
Tips:
1.明明是上傳,為什么是使用的receive指令?
上傳是針對于本機使用者,而對于服務(wù)器這樣的行為就是接收。同理,對于本機是下載則對于服務(wù)器是上傳。通過配置下載觸發(fā)器參數(shù)也可看出這點,下載觸發(fā)器配置的是send-zmodem這個文件。
2.名詞解釋:Regular expression
正則表達式
3. rz 、sz 是什么意思?
rz 即 recv-zmodem,receive zmodem 接收協(xié)議(對服務(wù)器),對本機表現(xiàn)為上傳。
sz 即 send-zmodem,send zmodem 發(fā)送協(xié)議(對服務(wù)器),對本機表現(xiàn)為下載。
zmodem 是一種傳輸協(xié)議(屬于SecureCRT),該協(xié)議只能可靠地傳輸大小不超過4GB的文件。
參考:
SecureCRT 上傳下載
wiki ZMODEM
wiki SecureCRT