Mac iTerm2 配置lrzsz

Posted 或许名字不重要

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mac iTerm2 配置lrzsz相关的知识,希望对你有一定的参考价值。

从csdn copy过来的,怕以后链接找不到

1.安装lrzsz(要先安装brew)

brew install lrzsz
2.配置

cd /usr/local/bin
   在/usr/loal/bin 目录下创建两个文件

命令:

vi iterm2-recv-zmodem.sh
vi iterm2-send-zmodem.sh
创建好两个文件后分别添加内容:

1. iterm2-recv-zmodem.sh

#!/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

2. iterm2-send-zmodem.sh

#!/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-*
配置好配置文件之后,开始对iTerm2进行配置

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

 

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(你要下载的文件的名字) 回车,会弹出窗体 我们选择要保存的地方即可。
————————————————
版权声明:本文为CSDN博主「姜无忧」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/xiasohuai/article/details/100775272

以上是关于Mac iTerm2 配置lrzsz的主要内容,如果未能解决你的问题,请参考以下文章

Mac iTerm2 配置lrzsz

mac下iterm2配置安装,通过expact实现保存账号,及通过跳板登陆配置

mac iterm2 配置sz&rz命令

mac系统vscode环境配置,以及iTerm2配置Zsh + on-my-zsh shell

在Mac机器上给ITerm2配置lrzsz,便捷的传输文件到远程服务器上

mac安装iterm2