Skip to content

Commit

Permalink
rzsz上传下载
Browse files Browse the repository at this point in the history
  • Loading branch information
snow-sprite committed Dec 10, 2019
0 parents commit 2e3520b
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 0 deletions.
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# iterm2 rz与sz的功能

本文主要介绍`mac`环境下使用`iterm2``rzsz`功能的安装流程。
> ** tips: 这两个文件本人也找了好久,有用的话请不要吝啬star **
## 1. 安装lrzsz

```bash
brew install lrzsz #可以在等待安装的过程中执行第2步
```

## 2. 安装执行脚本

``iterm2-send-zmodem.sh````iterm2-recv-zmodem.sh``保存到`/usr/local/bin`目录下。





## 3. 给这两个文件可执行权限(必须)

```bash
chmod 777 /usr/local/bin/iterm2-*
```

## 4. 设置Iterm2的Tirgger特性

设置Iterm2的Tirgger特性,profiles->default->editProfiles->Advanced中的Tirgger

添加两条trigger,分别设置 Regular expression,Action,Parameters,Instant如下:

```bash
Regular expression: rz waiting to receive.\*\*B0100
Action: Run Silent Coprocess
Parameters: /usr/local/bin/iterm2-send-zmodem.sh
Instant: checked

Regular expression: \*\*B00000000000000
Action: Run Silent Coprocess
Parameters: /usr/local/bin/iterm2-recv-zmodem.sh
Instant: checked
```

示例图:

<img src="https://raw.githubusercontent.com/snow-sprite/rzsz/master/triggers.jpg">

## 5. 在服务器端使用

- 上传文件:rz
- 下载文件:sz file1 file2 file(n)...

参考:

- https://www.robberphex.com/use-zmodem-at-macos/
- https://github.com/RobberPhex/iterm2-zmodem
26 changes: 26 additions & 0 deletions iterm2-recv-zmodem.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/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 --rename --escape --binary --bufsize 4096
sleep 1
echo
echo
echo \# Sent \-\> $FILE
fi
32 changes: 32 additions & 0 deletions iterm2-send-zmodem.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
###
# @Author: your name
# @Date: 2019-12-11 01:03:06
# @LastEditTime: 2019-12-11 01:03:21
# @LastEditors: your name
# @Description: In User Settings Edit
# @FilePath: /rzsz/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" --escape --binary --bufsize 4096
sleep 1
echo
echo \# Received "$FILE"
fi
Binary file added triggers.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2e3520b

Please sign in to comment.