php中的sz和rz,在iTerm2中使用Zmodem(rz,sz)的方法

本文介绍了如何在iTerm中通过Trigger功能设置sz和rz命令,实现便捷的远程主机文件传输。首先确保安装了iTerm Build 1.0.0.20120724及以上版本以及lrzsz套件。接着,将iterm2-zmodem提供的脚本放在指定路径并修改以适配实际安装位置。最后,在iTerm的触发器设置中配置相应的正则表达式和执行脚本,即可在Terminal中使用sz和rz进行文件收发。
摘要由CSDN通过智能技术生成

iTerm通过trigger的方式可以使用sz、rz命令方便的通过Terminal在远程主机文件传输。

设置方法

首先需要安装iTerm Build 1.0.0.20120724以上版本,因为从这个版本开始支持trigger。

然后使用port安装sz、rz:

1$sudoportinstalllrzsz

通过链接中“iterm2-zmodem”的说明,分别把iterm2-recv-zmodem.sh、iterm2-send-zmodem.sh放到/usr/local/bin/下,并加上可执行权限。

这里需要做一点小改动,脚本本身需要执行mac的sz、rz,port安装后是在/opt/local/bin/下,而作者的是/usr/local/bin/下,这里需要手动修改一下。

这是修改后的:

iterm2-recv-zmodem.sh

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

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

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)&"")"`

if[[$FILE=""]];then

echoCancelled.

# Send ZModem cancel

echo-ex18x18x18x18x18

echo# Cancelled transfer

echo

else

echo$FILE

cd"$FILE"

#/usr/local/bin/rz

/opt/local/bin/rz

echo# Received $FILE

echo

fi

iterm2-send-zmodem.sh

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

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

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)&"")"`

if[[$FILE=""]];then

echoCancelled.

# Send ZModem cancel

echo-ex18x18x18x18x18

echo# Cancelled transfer

echo

else

echo$FILE

#/usr/local/bin/sz "$FILE"

/opt/local/bin/sz"$FILE"

echo# Received $FILE

echo

fi

修改iTerm2的default trigger(iTerm偏好设置-> Profiles -> Default -> Advanced -> Triggers的Edit按钮):

1

2

3

4

5

6

7Regularexpression:**B0100

Action:RunSilentCoprocess

Parameters:/usr/local/bin/iterm2-send-zmodem.sh

Regularexpression:**B00000000000000

Action:RunSilentCoprocess

Parameters:/usr/local/bin/iterm2-recv-zmodem.sh

相关链接

iTerm2下载:

http://code.google.com/p/iterm2/downloads/list

iTerm2 trigger说明:

http://www.iterm2.com/triggers.html#/section/home

iterm2-zmodem脚本:

https://github.com/mmastrac/iterm2-zmodem

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值