如果没有额外的设置,iterm2 使用 rzsz 的时候会卡在
waiting to receive.**B0100000023be50
这个时候就需要使用iterm2提供的trigger来实现rzsz的功能。
第一步:本机安装rzsz
使用rzsz之前本地也需要安装
brew install lrzsz
如果没有安装brew,请先安装brew,mac必备的包管理器!
第二步:创建发送和接收脚本
发送文件的脚本如下,可以复制下面的内容,保存在 /usr/local/bin/iterm2-send-zmodem.sh中。
#!/bin/bash # Author: Matt Mastracci ([email protected]) # 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 $FILEfi vim /usr/local/bin/iterm2-send-zmodem.sh chmod +x /usr/local/bin/iterm2-send-zmodem.sh
接收文件的脚本如下,同样可以复制保存在/usr/local/bin/iterm2-recv-zmodem.sh
#!/bin/bash # Author: Matt Mastracci ([email protected]) # 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 vim /usr/local/bin/iterm2-recv-zmodem.sh<br>chmod +x /usr/local/bin/iterm2-recv-zmodem.sh
第三步:设置Trigger
teigger需要设置两个,一个实发送文件的trigger,一个是接收文件的trigger。
打开iterm2->Preferences->Profiles->Advanced->Triggers
点击Edit,点击+号,几个框分别填入下面的内容
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
最后设置好结果,这样每次换电脑都需要设置一遍,记录下来备忘。