前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >macOS 下 iTerm 如何安装 rzsz

macOS 下 iTerm 如何安装 rzsz

原创
作者头像
发声的沉默者
修改2021-06-15 11:13:12
5450
修改2021-06-15 11:13:12
举报
文章被收录于专栏:江歌闲谈江歌闲谈

Homebrew

安装:

$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

安装过程中,需要输入密码和确认

image
image
image
image

如果安装过程中遇到:$ Git download : error: RPC failed; curl 18 transfer closed with outstanding read data remaining,则说明你需要代理,设置 GitHub 代理,

$ git config --global https.proxy http://127.0.0.1:端口号

$ git config --global http.proxy http://127.0.0.1:端口号

安装成功:

image
image

可以通过 $ brew --help 测试是否安装成功

卸载:

$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh)"

安装 lrzsz

$ brew install lrzsz

安装完成后,进入 $ cd /usr/local/bin

创建文件并添加内容

代码语言:txt
复制
$ vi iterm2-recv-zmodem.sh
$ vi iterm2-send-zmodem.sh

创建好后,两个文件后分别添加内容

  1. iterm2-recv-zmodem.sh:
代码语言:txt
复制
#!/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
  1. iterm2-send-zmodem.sh:
代码语言:txt
复制
#!/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-*

编辑 iTerm

点击 iTerm2 的设置界面 Perference-> Profiles -> Default -> Advanced -> Triggers 的 Edit 按钮,加入以下配置:

image
image
代码语言:txt
复制
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

测试

rz 上传功能:在 bash 中,也就是 iTerm2 终端输入 rz 会弹出文件选择框,选择文件 choose 就开始上传,会上传到当前目录

sz 下载功能:sz fileName(你要下载的文件的名字) 回车,会弹出窗体,我们选择要保存的地方即可。

博客

欢迎关注我的博客

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Homebrew
  • 安装 lrzsz
  • 创建文件并添加内容
  • 编辑 iTerm
  • 测试
  • 博客
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档