Skip to content

Instantly share code, notes, and snippets.

@konn
Last active August 29, 2015 14:26
Show Gist options
  • Select an option

  • Save konn/a38a34f7749fffe5ae9c to your computer and use it in GitHub Desktop.

Select an option

Save konn/a38a34f7749fffe5ae9c to your computer and use it in GitHub Desktop.
zsh hooks を使って ssh / mosh の接続先によって Terminal.app のテーマを変える ref: http://qiita.com/mr_konn/items/68fb9af87cf20a217a84
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 # host name
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