前言
不知道小伙伴們是否遇到和我一樣的問題抠艾,在Mac上的iTerm2終端使用rz/sz功能時,一執(zhí)行就卡死桨昙,卡的死死的检号,只能關(guān)閉當(dāng)前窗口(或者一直等腌歉,等很長很長時間)。像這樣齐苛。翘盖。。凹蜂。
image.png
安裝rz馍驯、sz
#安裝
brew install lrzsz
#升級
brew upgrade lrzsz
配置
1.進(jìn)入到/usr/local/bin目錄
cd /usr/local/bin
2.在當(dāng)前目錄下創(chuàng)建兩個文件,編輯文件1:
vi 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
3.編輯文件2:
vi 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
4.修改文件權(quán)限
chmod 777 iterm2-recv-zmodem.sh
chmod 777 iterm2-send-zmodem.sh
5.打開iTerm2終端的設(shè)置界面 Perference-> Profiles -> Default -> Advanced -> Triggers 的 Edit 按鈕
image.png
6.點(diǎn)擊左下角的“+”,配置以下內(nèi)容
Regular expression: \*\*B0100
Action: Run Silent Coprocess
Parameters: /usr/local/bin/iterm2-send-zmodem.sh
Regular expression: \*\*B00000000000000
Action: Run Silent Coprocess
Parameters: /usr/local/bin/iterm2-recv-zmodem.sh
image.png
配置完成,可以執(zhí)行命令試一下啦玛痊!
rz 上傳
sz filename 下載
image.png