mac环境iterm2配置

iterm2下载地址

https://iterm2.com/downloads.html

安装oh-my-zsh

1、在线安装方式:

sh -c “$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

2、离线安装方式:

下载: https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh

安装: sh install.sh

安装Powerline

sudo easy_install pip
pip install powerline-status

安装 Meslo 字体库

# clone
git clone https://github.com/powerline/fonts.git --depth=1
# install
cd fonts
./install.sh
# clean-up a bit
cd ..
rm -rf fonts

配置item2

(iTerm2>Preferences>Profiles>Text>Change Font) -w953

使用solarized配色方案

-w925

安装agnoster(oh-my-zsh)主题

vi .zshrc # 修改ZSH_THEME

-w635

插件配置

# vim .zshrc
# 插件配置
plugins=(git history history-substring-search node npm wd web-search last-working-dir zsh-autosuggestions)

命令提示符前缀

# vim .oh-my-zsh/themes/agnoster.zsh-theme
#
### Prompt components
# Each component will draw itself, and hide itself if no information needs to be shown

# Context: user@hostname (who am I and where am I)
prompt_context() {
  if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
    prompt_segment black default "👍%(!.%{%F{yellow}%}.)%n@%m"
  fi
}

修改默认shell

chsh -s /bin/zsh
# 查看当前shell
echo #SHELL

上传下载(lrzsz)

安装: mac: brew install lrzsz linux: yum install lrzsz # apt-get install lrzsz 使用的两个shell脚本:iterm2-send-zmodem.sh and iterm2-recv-zmodem.sh ,保存到/usr/local/bin iterm2-send-zmodem.sh

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

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

iterm2-recv-zmodem.sh

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

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 --rename --escape --binary --bufsize 4096
    sleep 1
    echo
    echo
    echo \# Sent \-\> $FILE
fi
# 在 / usr/loal/bin 目录下创建两个文件
cd /usr/local/bin
wget https://raw.githubusercontent.com/RobberPhex/iterm2-zmodem/master/iterm2-recv-zmodem.sh
wget https://raw.githubusercontent.com/RobberPhex/iterm2-zmodem/master/iterm2-send-zmodem.sh

# 赋予这两个文件可执行权限
chmod 777 /usr/local/bin/iterm2-*

设置: Tirgger

Regular expression: rz waiting to receive.\*\*B0100
Action: Run Silent Coprocess
Parameters: /usr/local/bin/iterm2-send-zmodem.sh
Instant: checked

Regular expression: \*\*B00000000000000
Action: Run Silent Coprocess
Parameters: /usr/local/bin/iterm2-recv-zmodem.sh
Instant: checked

点击 iTerm2 的设置界面 Perference-> Profiles -> Default -> Advanced -> TriggersEdit 按钮,加入以下配置

添加两条 trigger,分别设置 Regular expressionAction,ParametersInstant 如下: -w923

上传下载2(trzsz)

说明: lrzsz太为常用,被公司封禁

引用链接:https://trzsz.github.io/cn/iterm2

github: https://github.com/trzsz/trzsz

安装:

mac:brew update && brew install trzsz

linux: pip install trzsz

配置:

  • trzsz命令路径:
which trzsz-iterm2
/usr/local/bin/trzsz-iterm2
  • 配置iterm2 打开 iTerm -> Preferences... -> Profiles -> ( 在左边选中一个 Profile ) -> Advanced -> Triggers -> Edit -> [+],如下配置:
Name Value 说明
Regular Expression :(:TRZSZ:TRANSFER:[SR]:\d+\.\d+\.\d+:\d+) 前后没有空格
Action Run Silent Coprocess...
Parameters /usr/local/bin/trzsz-iterm2 \1 前后没有空格
Enabled 勾选
  • 不要选中最下面的 Use interpolated strings for parameters。
  • 注意 /usr/local/bin/trzsz-iterm2 要替换成真实的 trzsz-iterm2 绝对路径。
  • 不同 Profile 的 Trigger 是互相独立的,也就是每个用到的 Profile 都要进行配置。
  • Trigger 的配置是允许输入多行的,但只会显示一行,注意不要多复制了一个换行符进去。 -w918
  • 打开 iTerm2 -> Preferences... -> General -> Magic,选中 Enable Python API-w679

  • 设置 ITERM2_COOKIE 环境变量可以使启动速度更快。 打开 iTerm2 -> Preferences... -> Advanced,筛选 COOKIE,选择 Yes-w1004

进度条配置

text进度条

屏幕录制 2022-05-01 时间 下午5.25.52 2

  • 升级 iTerm2 到 Build 3.5.20220327-nightly 以上的版本。
  • Trigger 的 Parameters 配置增加 -p text 参数。 /usr/local/bin/trzsz-iterm2 -p text \1 注意 /usr/local/bin/trzsz-iterm2 要替换成真实的 trzsz-iterm2 绝对路径。

zenity进度条

屏幕录制 2022-05-01 时间 下午5.35.11

  • 安装 zenity brew install ncruces/tap/zenity
  • 如果 Mac M1 安装失败,可以试试用 go 进行编译安装: brew install go go install 'github.com/ncruces/zenity/cmd/zenity@latest' sudo cp ~/go/bin/zenity /usr/local/bin/zenity
  • 执行 ls -l /usr/local/bin/zenity 应该输出 zenity 可执行文件或软链。不然可以建个软链: sudo ln -sv $(which zenity) /usr/local/bin/zenity

默认保存路径

如果你想自动下载文件到指定目录,而不是每次都弹窗询问。

例如,自动下载文件到 /Users/xxxxx/Downloads

  • 使用文本进度条,将 /usr/local/bin/trzsz-iterm2 -p text \1 改为: /usr/local/bin/trzsz-iterm2 -p text -d '/Users/xxxxx/Downloads' \1
  • 使用 zenity 进度条,将 /usr/local/bin/trzsz-iterm2 \1 改为: /usr/local/bin/trzsz-iterm2 -p zenity -d '/Users/xxxxx/Downloads' \1 注意 /usr/local/bin/trzsz-iterm2 要替换成真实的 trzsz-iterm2 绝对路径。

history问题(zsh)

linux记录历史命令到文件不生效时增加以下配置

# vi  .zshrc
# 增加一行
precmd () { eval "$PROMPT_COMMAND" }

session复制

增加下面配置文件后复制session便不再需要重新输入密码。

# vim .ssh/config

Host *
ServerAliveInterval 30
ControlMaster auto
ControlPath ~/.ssh/master-%r@%h:%p
ControlPersist yes

本文链接:参与评论 »

--EOF--

提醒:本文最后更新于 727 天前,文中所描述的信息可能已发生改变,请谨慎使用。

专题「其他」的其它文章 »

Comments