配置rz sz 进行上传下载
要想使用rz 和sz进行上传下载我们要尽兴一些配置
- 进入到/usr/local/bin 目录下
cd /usr/local/bin
-
这个目录下需要两个配置文件,这个配置文件可以自己粘贴,也可以去github网站下载。
- github网址: https://github.com/mmastrac/i...
- 如果不会下载就在github上打开文件 自己创建两个文件 并把内容粘贴进去
- 这里把我的配置过程和配置文件内容粘贴出来给大家,方便大家操作。
- 在/usr/loal/bin 目录下创建两个文件
命令:
vi iterm2-recv-zmodem.sh
vi iterm2-send-zmodem.sh
创建好两个文件后分别添加内容:
- iterm2-recv-zmodem.sh
#!/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
- iterm2-send-zmodem.sh
#!/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
- 将文件写好后保存好,使用如下命令添加权限
chmod +777 iterm2-*
- 配置好配置文件之后,开始对iTerm2进行配置
iTerm2 配置添加rz sz 功能
- 点击 iTerm2 的设置界面 Perference-> Profiles -> Default -> Advanced -> Triggers 的 Edit 按钮
--- 在最后一个图片的位置进行配置,上图是配置好的样子,配置文件如下:
Regular expression: rz waiting to receive.\*\*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
按照上面的配置文件信息的格式填写即可。
我照着这个操作遇到了一点坑,记录一下
操作完成后仍然不能上传下载,iterm上面给出报错,第一次没有view log,直接ignore,然后先改了trigger配置
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
仍然不行,然后到同事那拷贝了上面两个shell文件,还不行,但这次我看了log,提示权限不足,于是我执行chmod +777 iterm2-*,提示命令失败,然后我执行sudo chmod +777 iterm2-*,还是失败,目测是mac不认识+777,然后执行sudo chmod +x iterm2-*,然后就成功了。当然也可能是我的shell文件有问题。