iterm2 (1) -mac iterm2 installation lrzsz can use rz and sz uploading and downloading files to a remote server

 

 

 

Zmodem used in the method iTerm2

iTerm can use the trigger sz by the way, rz command easily through Terminal remote host file transfer.
First you need to install iTerm Build 1.0.0.20120724 or later, because from this version supports the trigger.

premise:

Mac comes first terminal does not support lrzsz, you need to download and install iterm2, Download:

http://www.iterm2.cn/download

Also you need to install homebrew to download other

brew has been installed and iterm2

 

1. Installation lrzsz (BREW first installed, if there is no need to install homeBrew installed, the installation is complete inspection ls -alh / usr / local / bin / sz presence or absence)

brew install lrzsz

2. Add the trigger

After a successful installation is to create two scripts to lrszs command / usr / local / bin directory, script address:

cd /usr/local/bin

   Creates two files in / usr / loal / bin directory

command:

we iterm2-recv-zmodem.sh 
we iterm2-send-zmodem.sh

 

Add contents were created two files:

1. iterm2-recv-zmodem.sh

 1 #!/bin/bash
 2 # Author: Matt Mastracci ([email protected])
 3 # AppleScript from http://stackoverflow.com/questions/4309087/cancel-button-on-osascript-in-a-bash-script
 4 # licensed under cc-wiki with attribution required 
 5 # Remainder of script public domain
 6  
 7 osascript -e 'tell application "iTerm2" to version' > /dev/null 2>&1 && NAME=iTerm2 || NAME=iTerm
 8 if [[ $NAME = "iTerm" ]]; then
 9     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)&\"\")"`
10 else
11     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)&\"\")"`
12 fi
13  
14 if [[ $FILE = "" ]]; then
15     echo Cancelled.
16     # Send ZModem cancel
17     echo -e \\x18\\x18\\x18\\x18\\x18
18     sleep 1
19     echo
20     echo \# Cancelled transfer
21 else
22     cd "$FILE"
23     /usr/local/bin/rz -E -e -b
24     sleep 1
25     echo
26     echo
27     echo \# Sent \-\> $FILE
28 fi
29  

 

2. iterm2-send-zmodem.sh

 

 1 #!/bin/bash
 2 # Author: Matt Mastracci ([email protected])
 3 # AppleScript from http://stackoverflow.com/questions/4309087/cancel-button-on-osascript-in-a-bash-script
 4 # licensed under cc-wiki with attribution required 
 5 # Remainder of script public domain
 6  
 7 osascript -e 'tell application "iTerm2" to version' > /dev/null 2>&1 && NAME=iTerm2 || NAME=iTerm
 8 if [[ $NAME = "iTerm" ]]; then
 9     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)&\"\")"`
10 else
11     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)&\"\")"`
12 fi
13 if [[ $FILE = "" ]]; then
14     echo Cancelled.
15     # Send ZModem cancel
16     echo -e \\x18\\x18\\x18\\x18\\x18
17     sleep 1
18     echo
19     echo \# Cancelled transfer
20 else
21     /usr/local/bin/sz "$FILE" -e -b
22     sleep 1
23     echo
24     echo \# Received $FILE
25 fi 
26  

Save the file after a good written, use the following command to add permissions

chmod 777 iterm2- *
Once configured profiles, begin to configure iTerm2

Click iTerm2 settings interface Perference-> Profiles -> Default -> Advanced -> Triggers the Edit button, add the following configuration

In the pop-up interface point "+" to add two parameters, namely:

\*\*B010                                  Run Silent Coprocess        /usr/local/bin/iterm2-send-zmodem.sh

\*\*B00000000000000              Run Silent Coprocess        /usr/local/bin/iterm2-recv-zmodem.sh

The red line, the contents of the box is also OK; Added after click "Close" to complete the configuration.

1 Regular expression: rz waiting to receive.\*\*B0100
2 Action: Run Silent Coprocess
3 Parameters: /usr/local/bin/iterm2-send-zmodem.sh
4  
5 Regular expression: \*\*B00000000000000
6 Action: Run Silent Coprocess
7 Parameters: /usr/local/bin/iterm2-recv-zmodem.sh
8  

 

 

 

Remarks:

rz upload function: In bash, which is iTerm2 input terminal rz file selection box will pop up, select the file you choose to start uploading, uploaded to the current directory
sz download: sz fileName (the name you want to download the file) Enter , will pop up a window where we can choose to save.

 

Reference: https: //blog.csdn.net/xiasohuai/article/details/100775272

 

Guess you like

Origin www.cnblogs.com/yiyaxuan/p/12545655.html