Skip to content

Instantly share code, notes, and snippets.

@marzocchi
Created April 1, 2017 11:36
Show Gist options
  • Save marzocchi/a2993ee75a4be887cbf6b31276786e35 to your computer and use it in GitHub Desktop.
Save marzocchi/a2993ee75a4be887cbf6b31276786e35 to your computer and use it in GitHub Desktop.
Use bindkey to track terminal focused state
function got-focus() {
echo $(date) $TTY got focus >> ~/focus.log
export ACTIVE=1
}
function lost-focus() {
echo $(date) $TTY lost focus >> ~/focus.log
export ACTIVE=0
}
on-prompt() {
echo $(date) $TTY showing prompt\; "active?" $ACTIVE >> ~/focus.log
}
zle -N lost-focus
zle -N got-focus
autoload add-zsh-hook
add-zsh-hook precmd on-prompt
printf "\033[?1004h"
bindkey "\033[O" lost-focus
bindkey "\033[I" got-focus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment