mac下item2配置rz和sz-避坑笔记

本文详细介绍了如何在配备Apple M1芯片的Mac上安装Homebrew,接着通过Homebrew安装lrzsz工具。随后,提供了两个自定义脚本(iterm2-recv-zmodem.sh和iterm2-send-zmodem.sh),用于在iTerm2中接收和发送文件,并指导如何根据系统路径调整脚本内容。最后,演示了在iTerm2中设置触发器以实现ZModem文件传输的自动化操作。
摘要由CSDN通过智能技术生成

我的mac信息:Apple M1 macOS Big Sur 11.4 (文末有截图)

1:安装Homebrew

已安装的忽略~~~
网上有很多安装教程,用的大部分都不可以,下面这个作者将所以过程都可视化的展示出来,懂中文的一看便会!!!赞

# 安装命令:
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

执行完后,要按照提示,退出重新打开item2或者 source 一下你的 .zprofile
来源链接:https://zhuanlan.zhihu.com/p/111014448

2:安装lrzsz

brew install lrzsz

备注:这一步如果有报错信息,一般就是你的Homebrew安装失败了,用第一步上面的安装命令重新安装接口,它会自动给你卸载掉旧版本。

3:配置脚本

网上都说这两个脚本,要放在cd /usr/local/bin 这个目录下,但item2配置的话,是可以放在任意自定义文件夹下的,只要item2里配置目录对应起来即可~~~

vi iterm2-recv-zmodem.sh

#!/bin/bash

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
	#/opt/homebrew/bin/rz -E -e -b # 注意:这是我的配置
	sleep 1
	echo
	echo
	echo \# Sent \-\> $FILE
fi

vi iterm2-send-zmodem.sh

#!/bin/bash

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
	# /opt/homebrew/bin/sz "$FILE" -e -b # 注意:这是我的配置
	sleep 1
	echo
	echo \# Received $FILE
fi

注意:我这两个脚本和网上给的不一样!不一样!不一样!
需要注意的是iterm2-recv-zmodem.sh 的第19行 和 iterm2-send-zmodem.sh 的第17行
要换成系统里 rz 和 sz 的默认路径
可以通过一下命令查看
在这里插入图片描述
像我的系统,lrzs默认放在了 /opt/homebrew/bin/ 下,
我就需要将两个脚本中的 rz 和 sz 的目录替换成自己的路径!!!
但注意:需要配置可执行权限
chmod 755 iterm2-*.sh
不然到item2中使用的时候,会报错说
/usr/local/bin/sz No such file or directory~~~

4:item2配置

如图:Preferences中直接搜索 Triggers
然后 Edit
在这里插入图片描述
然后点击 + 号配置即可,注意:Parameters为第3步中脚本的完整路径!!!
instant 也要勾线上~
在这里插入图片描述
配置信息从这里复制~~~

Regular expression: \*\*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  # 这个可替换成自己自定义的文件路径

然后,就可以尽情使用了~~~
不放心的话,退出item2重新打开再试~

mac信息:
在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值