LoginSignup
0
0

More than 5 years have passed since last update.

Change ITerm's background image with John's Background Switcher when fullscreen.

Posted at

ITerm を最大化すると透明度がゼロになっちゃうんですよね。
せっかく John’s Background Switcher | John's Adventures を使って背景を変えてるのに、ちょっと寂しい……。

とゆーワケで、空の enter を押すたびに iterm の背景を変えるスクリプトを書きました。

iterm.zsh
# -*- sh -*-
image_index=1
WALLPAPERS_PATH=`find ~/Library/Containers -name Wallpapers`

change_background_picture() {
  if [ `tput cols` -eq 80 ]
  then
    osascript -e "tell application \"iTerm\"
                    set current_terminal to (current terminal)
                    tell current_terminal
                      set current_session to (current session)
                      tell current_session
                        delete background image path
                      end tell
                    end tell
                  end tell"

    zle accept-line
    return
  fi

  image_list=($WALLPAPERS_PATH/*)
  if [ -z "$BUFFER" ]
  then
    image_path=$image_list[$(( $RANDOM % $#image_list + 1 ))]
    osascript -e "tell application \"iTerm\"
                    set current_terminal to (current terminal)
                    tell current_terminal
                      set current_session to (current session)
                      tell current_session
                        set background image path to \"$image_path\"
                      end tell
                    end tell
                  end tell"
    zle reset-prompt
    zle accept-line
  else
    zle accept-line
  fi
}

zle -N change_background_picture
bindkey '^m' change_background_picture

.zshrc に以下のように追加してください。

source $ZDOTDIR/iterm.zsh

最大化されてるか否かは、カラム数が 80 であるか否かで判断してます。
最大化をやめて、カラム数が 80 になった状態で空の enter を押すと、背景は削除されます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0