当前位置:   article > 正文

Iterm2设置_item2

item2

Item2

1.安装item2

使用 homebrew 安装 item2
brew install item2
  • 1

可以打开 item2了使用了

查看所有 shell
cat /etc/shells
  • 1
查看当前 shell
echo $SHELL
  • 1
切换 shell
//切换到 base
chsh -s /bin/bash
//切换到 zsh
chsh -s /bin/zsh
  • 1
  • 2
  • 3
  • 4

2.安装插件

安装on-my-zsh

安装…

修改配置
vim ~/.zshrc
  • 1
保存配置
source ~/.zshrc
  • 1

3.配置expect自动登录

创建脚本
vim alecs.sh
  • 1
#!/usr/bin/expect -f
set user 用户名
set host ip地址
set password 密码
set port 端口号(一般是 22)
set timeout -1

spawn   ssh -o StrictHostKeyChecking=no -p $port $user@$host
expect "*assword:*"
send "$password\r"
interact
expect eof
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
配置 Iterm2

image-20220625214218700

4.安装 rz sz 上传下载

mac上使用brew 安装lrzsz
brew install lrzsz
  • 1
Linux 上使用 yum 安装 lrzsz
yum install -y lrzsz
  • 1
在mac上创建两个脚本
  • iterm2-recv-zmodem.sh
cd /usr/local/bin
vim iterm2-recv-zmodem.sh
如果执行失败就加上 sudo
sudo vim iterm2-recv-zmodem.sh
sudo chmod 777 iterm2-*
  • 1
  • 2
  • 3
  • 4
  • 5

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 --bufsize 4096
    sleep 1
    echo
    echo
    echo \# Sent \-\> $FILE
fi
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • iterm2-send-zmodem.sh
cd /usr/local/bin
vim iterm2-send-zmodem.sh
chmod 777 iterm2-* 
如果执行失败就加上 sudo
sudo vim iterm2-send-zmodem.sh
sudo chmod 777 iterm2-*
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

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" --escape --binary --bufsize 4096
    sleep 1
    echo
    echo \# Received $FILE
fi
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
配置 Iterm2

image-20220626013228432

image-20220626013242926

Regular expressionActionParametersInstantEnabled
**B00000000000000Run Silent Coprocess…/usr/local/bin/iterm2-recv-zmodem.sh都行
rz waiting to receive.**B0100Run Silent Coprocess…/usr/local/bin/iterm2-send-zmodem.sh都行
rz :上传
#在bash中,也就是iTerm2终端输入rz 就会弹出文件选择框,选择文件 choose 就开始上传,会上传到当前目录
rz
  • 1
  • 2
注意:单独用rz会有两个问题:上传中断、上传文件变化(md5不同),解决办法是上传是用rz -be,并且去掉弹出的对话框中“Upload files as ASCII”前的勾选。
-a, –ascii
-b, –binary 用binary的方式上传下载,不解释字符为ascii
-e, –escape 强制escape 所有控制字符,比如Ctrl+x,DEL等
rar,gif等文件文件采用 -b 用binary的方式上传。

文件比较大而上传出错的话,采用参数 -e
如果用不带参数的rz命令上传大文件时,常常上传一半就断掉了,很可能是rz以为上传的流中包含某些特殊控制字符,造成rz提前退出。

综上,请使用 rz  -be
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
sz :下载
#sz fileName(你要下载的文件的名字) 回车,会弹出窗体 我们选择要保存的地方即可。
sz aaa.txt
  • 1
  • 2

5.解决 No such file or directory

使用rz或者 sz后出现了这个错误

/usr/local/bin/iterm2-send-zmodem.sh: line 17: /usr/local/bin/sz: No such file or directory
  • 1

原因是:

由于我们使用 brew 安装lrzsz,我们的这个脚本在当前目录找不到lrzsz

lrzsz安装目录可以这样查看

brew list lrzsz                                                                                                      
/opt/homebrew/Cellar/lrzsz/0.12.20_1/bin/lrb
/opt/homebrew/Cellar/lrzsz/0.12.20_1/bin/lrx
/opt/homebrew/Cellar/lrzsz/0.12.20_1/bin/lrz
/opt/homebrew/Cellar/lrzsz/0.12.20_1/bin/lsb
/opt/homebrew/Cellar/lrzsz/0.12.20_1/bin/lsx
/opt/homebrew/Cellar/lrzsz/0.12.20_1/bin/lsz
/opt/homebrew/Cellar/lrzsz/0.12.20_1/bin/rz
/opt/homebrew/Cellar/lrzsz/0.12.20_1/bin/sz
/opt/homebrew/Cellar/lrzsz/0.12.20_1/share/man/ (2 files)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

关键是这俩

/opt/homebrew/Cellar/lrzsz/0.12.20_1/bin/rz
/opt/homebrew/Cellar/lrzsz/0.12.20_1/bin/sz
  • 1
  • 2
解决方式有两种
方式一 :创建软连接

在 /usr/local/bin/目录下创建软连接

sudo ln -s /opt/homebrew/Cellar/lrzsz/0.12.20_1/bin/rz  /usr/local/bin/rz

sudo ln -s /opt/homebrew/Cellar/lrzsz/0.12.20_1/bin/sz  /usr/local/bin/sz
  • 1
  • 2
  • 3
方式二:修改配置文件

修改 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 --bufsize 4096
    #/opt/homebrew/Cellar/lrzsz/0.12.20_1/bin/rz 换成你安装lrzsz的路径,刚才查到的那个
   /opt/homebrew/Cellar/lrzsz/0.12.20_1/bin/rz -E -e -b --bufsize 4096
    sleep 1
    echo
    echo
    echo \# Sent \-\> $FILE
fi
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26

**修改 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" --escape --binary --bufsize 4096
   #/opt/homebrew/Cellar/lrzsz/0.12.20_1/bin/sz 换成你安装lrzsz的路径,刚才查到的那个
   /opt/homebrew/Cellar/lrzsz/0.12.20_1/bin/sz "$FILE" --escape --binary --bufsize 4096
    sleep 1
    echo
    echo \# Received $FILE
fi
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

6.解决使用expect自动登录后,不能使用rz和sz命令的问题

将Mac本地的LC_CTYP环境变量设置成en_US

#不推荐直接修改,创建一个脚本,在脚本中执行
vim aliecs1.sh
  • 1
  • 2
#!/bin/sh
#将Mac本地的LC_CTYP环境变量设置成en_US,解决无法 rz 的问题
export LC_CTYPE=en_US
#这里是你expect自动登录的脚本
/Users/zhangzhiyuan/ssh/aliecs.sh
  • 1
  • 2
  • 3
  • 4
  • 5

将Iterm2 这里的aliecs.sh改成aliecs1.sh

image-20220625221758181

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号