動的にiTerm2の背景画像を変える
こんな感じのをzshrcに書く。この場合、@キーで画像が変わる。
image_list=("画像1" "画像2") # 絶対パス
image_index=1
bg() {
if [ -z "$BUFFER" ]; then
if test $image_index -eq 2; then
image_index=1
else
image_index=$(( $image_index + 1 ))
fi
image_path=$image_list[$image_index]
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"
else
zle self-insert '@'
fi
}
zle -N bg
bindkey '\@' bg
コマンドが空でエンターを押すと背景画像が変わる
image_list=("画像1" "画像2")
image_index=1
bg() {
if [ -z "$BUFFER" ]; then
if test $image_index -eq 2; then
image_index=1
else
image_index=$(( $image_index + 1 ))
fi
image_path=$image_list[$image_index]
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 bg
bindkey '^m' bg