From ec98cb6972729ad9bda9beb1e8c0beb75d46266a Mon Sep 17 00:00:00 2001 From: Aviv Rosenberg Date: Sun, 19 Apr 2015 08:29:36 +0300 Subject: [PATCH] Plugin for iTerm2 on OSX iTerm2 is a popular terminal emulator for OSX (https://www.iterm2.com). The plugin currently implements one function, iterm2_profile, which allows easily changing the currently selected user settings profile, without creating a new tab or window, just by calling the function. For example, this is handy for switching from a dark to a light colored profile without having to re-open anything. In addition, it also works within tmux running inside iTerm2. --- plugins/iterm2/iterm2.plugin.zsh | 38 ++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 plugins/iterm2/iterm2.plugin.zsh diff --git a/plugins/iterm2/iterm2.plugin.zsh b/plugins/iterm2/iterm2.plugin.zsh new file mode 100644 index 000000000..f7d4868b6 --- /dev/null +++ b/plugins/iterm2/iterm2.plugin.zsh @@ -0,0 +1,38 @@ +##################################################### +# iTerm2 plugin for oh-my-zsh # +# Author: Aviv Rosenberg (github.com/avivrosenberg) # +##################################################### + +### +# This plugin is only relevant if the terminal is iTerm2 on OSX. +if [[ "$OSTYPE" == darwin* ]] && [[ -n "$ITERM_SESSION_ID" ]] ; then + + ### + # iterm2_profile(): Function for changing the current terminal window's + # profile (colors, fonts, settings, etc). + # To change the current iTerm2 profile, call this function and pass in a name + # of another existing iTerm2 profile (name can contain spaces). + function iterm2_profile() { + # Desired name of profile + local profile="$1" + + # iTerm2 escape code for changing profile + local iterm2_code="\x1b]50;SetProfile=$profile\x7" + + # If we're in tmux, a special escape code must be prepended + # so that the iTerm2 escape code is passed on into iTerm2. + local prefix='' + local suffix='' + if [[ -n $TMUX ]]; then + prefix='\033Ptmux;\033' + suffix='\033\\' + fi + + # send the sequence + echo -n "${prefix}${iterm2_code}${suffix}" + + # update shell variable + ITERM_PROFILE="$profile" + } + +fi