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.
# Usage:
# 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
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