iTerm通过trigger的方式可以使用sz、rz命令方便的通过Terminal在远程主机文件传输。
设置方法
首先需要安装iTerm Build 1.0.0.20120724以上版本,因为从这个版本开始支持trigger。
然后使用port安装sz、rz:
|
1
|
$
sudo
port
install
lrzsz
|
通过链接中“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
echo
Cancelled.
#
Send ZModem cancel
echo
-e
\\x18\\x18\\x18\\x18\\x18
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
echo
Cancelled.
#
Send ZModem cancel
echo
-e
\\x18\\x18\\x18\\x18\\x18
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
7
|
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
|
2076

被折叠的 条评论
为什么被折叠?



