一、前置條件:
安裝好HomeBrew 和 iTerm2 绩聘,HomeBrew 已經(jīng)支持M1版本了沥割,正常安裝即可。
二凿菩、提前準(zhǔn)備文件:
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
進(jìn)入該文件夾下。
將剛才的兩個(gè)文件放入該文件夾玩郊,需要輸入密碼輸入登錄密碼即可肢执。
第三步:配置文件權(quán)限
打開iTerm2 ,輸入 cd /usr/local/bin
進(jìn)入該目錄译红。再輸入chmod 777 iterm2-*
調(diào)整文件權(quán)限為777预茄。
第四步:軟連接執(zhí)行文件(關(guān)鍵)
新版的brew路徑和老版本不同,上面兩個(gè)文件寫死了路徑,所以這里使用軟連接將文件指向進(jìn)行調(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
點(diǎn)擊iTerm2拙徽,選擇 Preference... -> Profiles -> Default -> Advanced -> Edit (in Triggers),如圖第六步:配置Edit中選項(xiàng)
可以看到每一個(gè)觸發(fā)器(Trigger)都有幾個(gè)選項(xiàng)需要配置诗宣。這里我們添加上傳和下載的觸發(fā)器膘怕。
其各個(gè)選項(xiàng)配置如下:
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 ,會(huì)彈出一個(gè)文件選擇器岛心,選擇后開始上傳。
Tips:
1.明明是上傳篮灼,為什么是使用的receive指令忘古?
上傳是針對(duì)于本機(jī)使用者,而對(duì)于服務(wù)器這樣的行為就是接收诅诱。同理髓堪,對(duì)于本機(jī)是下載則對(duì)于服務(wù)器是上傳。通過配置下載觸發(fā)器參數(shù)也可看出這點(diǎn)娘荡,下載觸發(fā)器配置的是send-zmodem這個(gè)文件干旁。
2.名詞解釋:Regular expression
正則表達(dá)式
3. rz 、sz 是什么意思它改?
rz 即 recv-zmodem疤孕,receive zmodem 接收協(xié)議(對(duì)服務(wù)器),對(duì)本機(jī)表現(xiàn)為上傳央拖。
sz 即 send-zmodem祭阀,send zmodem 發(fā)送協(xié)議(對(duì)服務(wù)器),對(duì)本機(jī)表現(xiàn)為下載鲜戒。
zmodem 是一種傳輸協(xié)議(屬于SecureCRT)专控,該協(xié)議只能可靠地傳輸大小不超過4GB的文件。
參考:
SecureCRT 上傳下載
wiki ZMODEM
wiki SecureCRT