Skip to content

Instantly share code, notes, and snippets.

@wangchen
Last active November 3, 2021 16:11
Show Gist options
  • Save wangchen/18b037ceb009fcb0df87 to your computer and use it in GitHub Desktop.
Save wangchen/18b037ceb009fcb0df87 to your computer and use it in GitHub Desktop.

Revisions

  1. wangchen revised this gist Jul 31, 2015. 1 changed file with 6 additions and 9 deletions.
    15 changes: 6 additions & 9 deletions iterm2.zsh
    Original file line number Diff line number Diff line change
    @@ -1,17 +1,14 @@
    # Usage:
    # source iterm2.zsh
    # Change profile when using ssh.
    # You MUST define a profile named 'ForSSH' with diferent settings.
    # I am using color schemes with different background color.
    # Then:
    # $ save as ~/.iterm2.zsh
    # $ echo ". ~/.iterm2.zsh" >> ~/.zshrc

    # iTerm2 window/tab color commands
    # Requires iTerm2 >= Build 1.0.0.20110804
    # http://iterm2.com/documentation-escape-codes.html
    tab-color() {
    echo -ne "\033]6;1;bg;red;brightness;$1\a"
    echo -ne "\033]6;1;bg;green;brightness;$2\a"
    echo -ne "\033]6;1;bg;blue;brightness;$3\a"
    }
    tab-reset() {
    echo -ne "\033]6;1;bg;*;default\a"
    }

    profile-change() {
    echo -ne "\033]50;SetProfile=ForSSH\a"
  2. wangchen revised this gist Jul 31, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion iterm2.zsh
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@

    # iTerm2 window/tab color commands
    # Requires iTerm2 >= Build 1.0.0.20110804
    # http://code.google.com/p/iterm2/wiki/ProprietaryEscapeCodes
    # http://iterm2.com/documentation-escape-codes.html
    tab-color() {
    echo -ne "\033]6;1;bg;red;brightness;$1\a"
    echo -ne "\033]6;1;bg;green;brightness;$2\a"
  3. wangchen created this gist Jul 31, 2015.
    35 changes: 35 additions & 0 deletions iterm2.zsh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    # Usage:
    # source iterm2.zsh

    # iTerm2 window/tab color commands
    # Requires iTerm2 >= Build 1.0.0.20110804
    # http://code.google.com/p/iterm2/wiki/ProprietaryEscapeCodes
    tab-color() {
    echo -ne "\033]6;1;bg;red;brightness;$1\a"
    echo -ne "\033]6;1;bg;green;brightness;$2\a"
    echo -ne "\033]6;1;bg;blue;brightness;$3\a"
    }
    tab-reset() {
    echo -ne "\033]6;1;bg;*;default\a"
    }

    profile-change() {
    echo -ne "\033]50;SetProfile=ForSSH\a"
    echo -ne "\033]50;SetProfile=ForSSH\a"
    }
    profile-reset() {
    echo -ne "\033]50;SetProfile=Default\a"
    }

    # Change the color of the tab when using SSH
    # reset the color after the connection closes
    color-ssh() {
    if [[ -n "$ITERM_SESSION_ID" ]]; then
    trap "profile-reset" INT EXIT
    profile-change
    fi
    ssh $*
    }
    compdef _ssh color-ssh=ssh

    alias ssh=color-ssh