Created
April 1, 2017 11:36
-
-
Save marzocchi/a2993ee75a4be887cbf6b31276786e35 to your computer and use it in GitHub Desktop.
Use bindkey to track terminal focused state
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
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