]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/plugins/iterm2/iterm2.plugin.zsh
...
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / plugins / iterm2 / iterm2.plugin.zsh
1 #####################################################
2 # iTerm2 plugin for oh-my-zsh                       #
3 # Author: Aviv Rosenberg (github.com/avivrosenberg) #
4 #####################################################
5
6 ###
7 # This plugin is only relevant if the terminal is iTerm2 on OSX.
8 if [[ "$OSTYPE" == darwin* ]] && [[ -n "$ITERM_SESSION_ID" ]] ; then
9
10   ###
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() {
15     local cmd="$1"
16
17     # Escape codes for wrapping commands for iTerm2.
18     local iterm2_prefix="\x1B]"
19     local iterm2_suffix="\x07"
20
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\\"
26     fi
27
28     echo -n "${tmux_prefix}${iterm2_prefix}${cmd}${iterm2_suffix}${tmux_suffix}"
29   }
30
31   ###
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
38     local profile="$1"
39
40     # iTerm2 command for changing profile
41     local cmd="1337;SetProfile=$profile"
42
43     # send the sequence
44     _iterm2_command "${cmd}"
45
46     # update shell variable
47     ITERM_PROFILE="$profile"
48   }
49
50   ###
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"
58   }
59
60
61   ###
62   # iterm2_tab_color_reset(): Resets the color of iTerm2's current tab back to
63   # default.
64   function iterm2_tab_color_reset() {
65     _iterm2_command "6;1;bg;*;default"
66   }
67
68 fi