mac ssh连接不同环境更换颜色

th?id=OHR.AiringGrievances_ZH-CN5830208720_1920x1080.jpg&rf=LaDigue_1920x1080.jpg&pid=hp.jpg

1、创建item主题


image.png

2、创建shell脚本

vim ~/.oh-my-zsh/custom/iTrem2-ssh.zsh

3、将以下内容写入脚本(iTrem2-ssh.zsh)中

# tabc <profile name> do the profile change
function tabc() {
  NAME=$1; if [ -z "$NAME" ]; then NAME="Default"; fi 
  # if you have trouble with this, change
  # "Default" to the name of your default theme
  echo -e "\033]50;SetProfile=$NAME\a"
}

# reset the terminal profile to Default  when exit from the ssh session
function tab-reset() {
    NAME="Default"
    echo -e "\033]50;SetProfile=$NAME\a"
}

# selecting different terminal profile according to ssh'ing host
# tabc <profile name> do the profile change
#   1. Production profile to production server (ssh eranga@production_box) 
#   2. Staging profile to staging server(ssh eranga@staging_box) 
#   3. Other profile to any other server(test server, amazon box etc)
function colorssh() {
    if [[ -n "$ITERM_SESSION_ID" ]]; then
        trap "tab-reset" INT EXIT
        if [[ "$*" =~ "dev*" ]]; then
            tabc dev
        elif [[ "$*" =~ "test*" ]]; then
            tabc test 
        elif [[ "$*" =~ "online*" ]]; then
            tabc online 
        else
            tabc Default
        fi
    fi
    ssh $*
}
compdef _ssh tabc=ssh

# creates an alias to ssh
# when execute ssh from the terminal it calls to colorssh function
alias ssh="colorssh"

4、修改ssh config 中的连接名称(名称中有关键词即可)
例1:ssh ***-online


image.png

例2:ssh test


image.png

5、分屏设置默认主题
vim ~/.bash_profile
# 在最底下填上这个
echo -e "\033]50;SetProfile=Default\a"
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容