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 ([email protected])
# 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 ([email protected])
# 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
相关推荐
xiaonianzuibang5 小时前
如何修复宝可梦时时刻刻冒险无法正常工作
macos·objective-c·cocoa
只会写bug的靓仔1 天前
mac 设置飞书默认浏览器(解决系统设置默认浏览器无效)
macos·飞书
尽兴-2 天前
Mac「brew」快速安装Redis
数据库·redis·macos·brew
尽兴-2 天前
Mac 「brew」快速安装MySQL
mysql·macos·adb·brew
明似水2 天前
macOS 更新后找不到钥匙串访问工具的解决方案
macos
一牛2 天前
Appkit: 菜单是如何工作的
macos·ios·objective-c
tkevinjd2 天前
文件操作、流对象示例
macos·objective-c·cocoa
Dachui_11223 天前
MacOS上如何运行内网穿透详细教程
macos
Bruce_Liuxiaowei3 天前
使用Python脚本在Mac上彻底清除Chrome浏览历史:开发实战与隐私保护指南
chrome·python·macos
iFlyCai3 天前
对Mac文字双击或三击鼠标左键没有任何反应
macos·计算机外设