当前位置: 首页 > article >正文

mac iterm2 使用 lrzsz

前言

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

mac 上安装

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 命令的路径

$ which rz
/opt/homebrew/bin/rz
$ which sz
/opt/homebrew/bin/sz
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
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

给脚本赋予权限

sudo chmod 777 /usr/local/bin/iterm2-*

配置 iterm2

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
注意 Action 列有下拉选项框,选择即可。其他列复制粘贴。
在这里插入图片描述
为方便复制

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

http://www.kler.cn/a/444268.html

相关文章:

  • 设计模式12:状态模式
  • 数智化转型是什么?
  • 音频接口:PDM TDM128 TDM256
  • JS设计模式之中介者模式
  • day38-SSH安全登录
  • Soul Android端稳定性背后的那些事
  • 微积分复习笔记 Calculus Volume 2 - 4.4 The Logistic Equation
  • 浏览器引入elasticsearch-head插件
  • tomcat(Web应用服务器)
  • 线性代数基础与应用:基底 (Basis) 与现金流及单期贷款模型(中英双语)
  • ACL-2024 | MapGPT:基于地图引导提示和自适应路径规划机制的视觉语言导航
  • 如何实现单例模式?
  • webpack处理图片资源
  • 【JavaEE进阶】关于Maven
  • macos控制台安装
  • C++ OpenGL学习笔记(1、Hello World空窗口程序)
  • 计算机网络-GRE Over IPSec实验
  • 递归读取指定目录下的文件
  • postman免登录步骤
  • AIGC:图像风格迁移技术实现猜想
  • 【多模态】MiniCPM-V多模态大模型使用学习
  • RTR Chaptor12
  • C语言基础:数组(字符数组)
  • url提取
  • HarmonyOS Next应用开发实战:ArkWeb组件使用介绍及使用举例
  • 【原创教程】西门子1500TCP_UDP通信说明大全(下篇)