mac iterm2 使用 lrzsz

前言

mac os 终端不支持使用 rz sz 上传下载文件,本文提供解决方法。

mac 上安装

bash 复制代码
brew install lrzsz

两个脚本

注意:/usr/local/bin/iterm2-send-zmodem.sh 中的 sz命令路径要和你mac 上 sz 命令路径一致。

/usr/local/bin/iterm2-recv-zmodem.sh 中的 rz 命令路径要和你 mac 上的 rz 命令路径一致。

查看 mac 上 rz 和 sz 命令的路径

bash 复制代码
$ which rz
/opt/homebrew/bin/rz
bash 复制代码
$ which sz
/opt/homebrew/bin/sz
bash 复制代码
cat > /usr/local/bin/iterm2-send-zmodem.sh < EOF
#!/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
    /opt/homebrew/bin/sz "$FILE" -e -b
    sleep 1
    echo
    echo \# Received $FILE
fi
EOF
bash 复制代码
cat > /usr/local/bin/iterm2-recv-zmodem.sh  << EOF
#!/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"
    /opt/homebrew/bin/rz -E -e -b
    sleep 1
    echo
    echo
    echo \# Sent \-\> $FILE
fi
EOF

给脚本赋予权限

bash 复制代码
sudo chmod 777 /usr/local/bin/iterm2-*

配置 iterm2




注意 Action 列有下拉选项框,选择即可。其他列复制粘贴。

为方便复制

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
相关推荐
看海的四叔1 小时前
【系统】Mac crontab 无法退出编辑模式问题
运维·macos·定时任务·crontab
liupenglove1 小时前
Elasticsearch8.17.0在mac上的安装
macos
satadriver5 小时前
macos控制台安装
macos
十八胡笳12 小时前
mac-m2安装mysql遇到的问题
mysql·macos
程序员 超超15 小时前
Stable Diffusion 安装教程(附安装包) 【SD三种安装方式,Win+Mac一篇文章讲明白】
人工智能·macos·ai作画·stable diffusion·midjourney
Roseann YAN15 小时前
macos big sur 软件icons图标大全(新增至2719枚大苏尔风格图标)
macos
益达是我1 天前
【Java】mac安装Java17(JDK17)
java·开发语言·macos
赵大仁1 天前
在M系列芯片的Mac上使用Uniapp开发的依赖安装指南
前端·windows·macos·ios·小程序·uni-app·安卓
竹杖芒鞋轻胜马,谁怕?一蓑烟雨任平生。1 天前
Mac升级macOS 15 Sequoia后,无法ssh连接本地虚拟机
运维·macos·ssh