mac ssh連接不同環(huán)境更換顏色

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

1、創(chuàng)建item主題


image.png

2、創(chuàng)建shell腳本

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

3、將以下內(nèi)容寫入腳本(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"
最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容