Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: command on switching terminals?
- X-seq: zsh-users 23054
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Ray Andrews <rayandrews@xxxxxxxxxxx>
- Subject: Re: command on switching terminals?
- Date: Sat, 6 Jan 2018 23:20:12 +0100
- Cc: Zsh Users <zsh-users@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=wAr0yzTwBWggPSHK6Q8i7K+5e1pCa+Fwi6gjYrbe6EA=; b=oGHAL6MQp3FG/xyRRFFzRyMv/TpMyoz8mmk/DuSab1rRrov3oAg/enyYOVkTVPpttT glqtt5lZXZTwR6Bd/z3ecFhBEsmp+ZQQs3UyBm40V8eOpkvdmIiV6jctgTyWJbPd+XlM PS1TFaLQTLcSxTjZGbqzlPIm5bbx4k59dVEpSZeTuUOBa3GacAggziXktsuRrkz3Kw9e S4MmEOwUM0PDjhk1bIq/ooxz1KNHlOYa+QmY+/FUYUUbJr6pCVlxdkZJMG+mAm5NB1g2 6+0b+8aiFsn0KwE2YX94kKBauLvZ2BnU6r16JHAOwl9Tv2eeCTK6ufTgdpvtvUlA1YFv PUXA==
- In-reply-to: <5dbdfef3-65c0-b780-76a8-86ed79c0d8e4@eastlink.ca>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <5dbdfef3-65c0-b780-76a8-86ed79c0d8e4@eastlink.ca>
On Sat, Jan 6, 2018 at 6:33 AM, Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
> Is it possible for zsh to know when the terminal in which it is running has
> awakened by having the mouse moved into that window? I understand that it's
> the window manager that decides which terminal is active of course, but
> perhaps zsh knows when it is put to sleep by the mouse moving out of it's
> window, and also knows when it has been awakened again? I have a utility
> that lets you hotkey a mouse jump between terminals so as to jump between
> them without having to reach for the mouse itself, and I can call it fine
> within a function, but I'd like to be able to also execute some code after
> each jump but in the new window. As it is, zsh just wakes up without
> seeming to know it's been asleep so there's nothing to 'attach' any commands
> to. precmd() and preexec() are not aroused. Any commands inside the
> calling function placed after the command to jump to the new terminal are
> executed in the old terminal, which is not surprising, so it would have to
> depend on the awakened terminal knowing it's been awakened. Sorta like
> precmd but hooked to the activation of the terminal. I understand that this
> might be outside of zsh's domain.
You can, yes. Note that if a program was running in the foreground,
zsh won't know if the terminal is active or not once that program
finishes though. I have never found a practical use for this.
# this might work for more terminals but i haven't tested, adjust as needed
# also check if you already have hooks for zle-line-init/finish and
adjust those as needed instead
# note also that leaving/entering a terminal will disable paste
hilighting when the following stuff is enabled
# These two hooks will enable and disable the terminal sending an
escape code to the terminal when it receives/loses focus, since most
programs won't handle them.
function _zle_line_init() {
# enable focus events
[[ $TERM == rxvt-unicode || $TERM = xterm ]] && printf '\e[?1004h'
}
function _zle_line_finish() {
# disable focus events
[[ $TERM == rxvt-unicode || $TERM = xterm ]] && printf '\e[?1004l'
}
zle -N zle-line-init _zle_line_init
zle -N zle-line-finish _zle_line_finish
# Handle FocusIn/Out events
bindkey '^[[I' focus-in
bindkey '^[[O' focus-out
# you can use two different functions too of course,
# i just happened to want the same thing to happen in both cases
# when i was testing this
zle -N focus-in _focus_handler
zle -N focus-out _focus_handler
function _focus_handler() {
# $WIDGET will be focus-in when terminal receives
# focus and focus-out when losing it, eg
if [[ $WIDGET = focus-in ]]; then
zle -M "hey we got focus"
fi
}
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author