1 #####################################################
2 # iTerm2 plugin for oh-my-zsh #
3 # Author: Aviv Rosenberg (github.com/avivrosenberg) #
4 #####################################################
7 # This plugin is only relevant if the terminal is iTerm2 on OSX.
8 if [[ "$OSTYPE" == darwin* ]] && [[ -n "$ITERM_SESSION_ID" ]] ; then
11 # Executes an arbitrary iTerm2 command via an escape code sequence.
12 # See https://iterm2.com/documentation-escape-codes.html for all supported commands.
13 # Example: $ _iterm2_command "1337;StealFocus"
14 function _iterm2_command() {
17 # Escape codes for wrapping commands for iTerm2.
18 local iterm2_prefix="\x1B]"
19 local iterm2_suffix="\x07"
21 # If we're in tmux, a special escape code must be prepended/appended so that
22 # the iTerm2 escape code is passed on into iTerm2.
23 if [[ -n $TMUX ]]; then
24 local tmux_prefix="\x1BPtmux;\x1B"
25 local tmux_suffix="\x1B\\"
28 echo -n "${tmux_prefix}${iterm2_prefix}${cmd}${iterm2_suffix}${tmux_suffix}"
32 # iterm2_profile(): Function for changing the current terminal window's
33 # profile (colors, fonts, settings, etc).
34 # To change the current iTerm2 profile, call this function and pass in a name
35 # of another existing iTerm2 profile (name can contain spaces).
36 function iterm2_profile() {
37 # Desired name of profile
40 # iTerm2 command for changing profile
41 local cmd="1337;SetProfile=$profile"
44 _iterm2_command "${cmd}"
46 # update shell variable
47 ITERM_PROFILE="$profile"
51 # iterm2_tab_color(): Changes the color of iTerm2's currently active tab.
52 # Usage: iterm2_tab_color <red> <green> <blue>
53 # where red/green/blue are on the range 0-255.
54 function iterm2_tab_color() {
55 _iterm2_command "6;1;bg;red;brightness;$1"
56 _iterm2_command "6;1;bg;green;brightness;$2"
57 _iterm2_command "6;1;bg;blue;brightness;$3"
62 # iterm2_tab_color_reset(): Resets the color of iTerm2's current tab back to
64 function iterm2_tab_color_reset() {
65 _iterm2_command "6;1;bg;*;default"