MAC 安装 ITerm2 并配置常用插件
2021-01-26 本文已影响0人
fanxcv
安装过程建议准备梯子,要不速度堪忧
1.安装iTerm2
到iTerm2官网下载安装
2.安装HomeBrew
执行以下脚本安装HomeBrew,脚本来自于HomeBrew官网
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
3.安装zsh
# mac os
brew install zsh
# centos
yum -y install zsh git
# debain ubuntu
apt install -y zsh git
4.安装 Oh My Zsh
安装脚本来自于Oh My Zsh官方仓库
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
5.修改皮肤文件(个人喜好,各位随意)
vim ~/.oh-my-zsh/themes/fishy.zsh-theme
6.加载皮肤
# mac os
sed -i '' 's/^\(ZSH_THEME=\)".*"$/\1"fishy"/g' ~/.zshrc
source ~/.zshrc
# linux
sed -i 's/^\(ZSH_THEME=\)".*"$/\1"fishy"/g' ~/.zshrc
source ~/.zshrc
7.添加插件
zsh-syntax-highlighting
# mac os
brew install zsh-syntax-highlighting
echo 'source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh' >> ~/.zshrc
source ~/.zshrc
# linux
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
sed -i 's/^\(plugins=[^)]*\))$/\1 zsh-syntax-highlighting)/g' ~/.zshrc
source ~/.zshrc
zsh-autosuggestions
# mac os
brew install zsh-autosuggestions
echo 'source /usr/local/share/zsh-autosuggestions/zsh-autosuggestions.zsh' >> ~/.zshrc
source ~/.zshrc
# linux
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
sed -i 's/^\(plugins=[^)]*\))$/\1 zsh-autosuggestions)/g' ~/.zshrc
source ~/.zshrc
8.添加sz rz命令支持
# 安装依赖lrzsz
brew install lrzsz
# iterm2-send-zmodem.sh
sudo cat <<EOF > /usr/local/bin/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
EOF
# iterm2-recv-zmodem.sh
sudo cat <<EOF > /usr/local/bin/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
EOF
# 添加权限
chmod a+x /usr/local/bin/iterm2-*
设置Iterm2的Tirgger特性,profiles->Advanced中的Tirgger
添加两条trigger,分别设置 Regular expression,Action,Parameters,Instant如下
1.第一条
Regular expression: rz waiting to receive.\*\*B0100
Action: Run Silent Coprocess
Parameters: /usr/local/bin/iterm2-send-zmodem.sh
Instant: checked
2.第二条
Regular expression: \*\*B00000000000000
Action: Run Silent Coprocess
Parameters: /usr/local/bin/iterm2-recv-zmodem.sh
Instant: checked