iTerm2安装教程
1.首先要有iTerm2
iTerm2官网下载地址:iTerm2下载链接
2.本地安装lrzxz
brew install lrzsz
3.下载iterm2-send-zmodem.sh 和 iterm2-recv-zmodem.sh脚本文件
iterm2-recv-zmodem
#!/bin/bash | |
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| | # 这个脚本来自 github,删掉了一些 ** 言论。 |
| | |
| | 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 --bufsize 4096 |
| | sleep 1 |
| | echo |
| | echo |
| | echo \# Sent \-\> $FILE |
| | fi
iterm2-send-zmodem.sh
#!/bin/bash | |
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| | # 这个脚本来自 github,删掉了一些 ** 言论。 |
| | |
| | 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" --escape --binary --bufsize 4096 |
| | sleep 1 |
| | echo |
| | echo \# Received $FILE |
| | fi
4.将这两个脚本文件保存到/usr/local/bin/ 路径下,cd到该目录下为其添加可执行权限。
cd /usr/local/bin/
chmod +x iterm2-send-zmodem.sh
chmod +x iterm2-recv-zmodem.sh
5.iterm2 添加 triggers
打开“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
遇到报错解决
一到远程服务器运行 rz 或者sz 就报错,错误是
/usr/local/bin/iterm2-send-zmodem.sh: line 18: /usr/local/bin/sz: No such file or directory
按照报错地址,在本地的“/usr/local/bin”下没有sz和rz,但是brew install lrzsz 已经安装成功
解决方案:
brew list lrzsz
找到安装位置,比如我的在
那么就去修改 iterm2-send-zmodem.sh 和 iterm2-recv-zmodem.sh 中的sz和rz的位置
rz、sz相同的方法