Last active
August 29, 2015 14:26
-
-
Save konn/721caba83fea88c1bf14 to your computer and use it in GitHub Desktop.
Auto Terminal BG change
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| autoload -Uz add-zsh-hook; | |
| unset __WINDOWLOC; | |
| unset __PREVSETID; | |
| function set_bg () { | |
| osascript -e "tell app \"Terminal\" to set the current settings of the tab ${__WINDOWLOC[1]} of window id ${__WINDOWLOC[2]} to settings set \"$1\"" | |
| } | |
| function ssh-mosh-observe() { | |
| mycmd=(${(s: :)${1}}); | |
| case ${mycmd[1]} in | |
| ssh|mosh) | |
| HOSTNAME=${mycmd[-1]}; | |
| __WINDOWLOC=(`osascript -e "tell app \"Terminal\" to selected tab of the window 1" | cut -d' ' -f 2,6`); | |
| __PREVSETID=`osascript -e "tell app \"Terminal\" to name of current settings of tab ${__WINDOWLOC[1]} of the window id ${__WINDOWLOC[2]}"`; | |
| case $HOSTNAME in | |
| sakura-vps) set_bg "Sakura";; | |
| ubuntu-vm) set_bg "VM";; | |
| *) set_bg "Pro";; | |
| esac;; | |
| esac | |
| } | |
| add-zsh-hook preexec ssh-mosh-observe | |
| function ssh-mosh-post() { | |
| if [ -n "${__WINDOWLOC-}" ]; then | |
| set_bg ${__PREVSETID}; | |
| unset __WINDOWLOC; | |
| unset __PREVSETID; | |
| fi | |
| } | |
| add-zsh-hook precmd ssh-mosh-post |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment