Skip to content

Instantly share code, notes, and snippets.

@wangchen
Last active November 3, 2021 16:11
Show Gist options
  • Select an option

  • Save wangchen/18b037ceb009fcb0df87 to your computer and use it in GitHub Desktop.

Select an option

Save wangchen/18b037ceb009fcb0df87 to your computer and use it in GitHub Desktop.
# Usage:
# source iterm2.zsh
# 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"
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
@wangchen
Copy link
Author

@eexit
Copy link

eexit commented Nov 3, 2021

Hello, does this still work? It used to work but it stopped lately...

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment