* Timing out a completion, a different tack
@ 2014-01-26 7:51 Bart Schaefer
0 siblings, 0 replies; only message in thread
From: Bart Schaefer @ 2014-01-26 7:51 UTC (permalink / raw)
To: zsh-users
The script below shows how to create a completer named _timeout that
sends zsh an INT signal after a number of seconds configured in the
"timeout" zstyle. It will also cause a message to be printed if the
completion is interrupted from the keyboard.
Add _timeout to the completer zstyle somewhere ahead of _complete
and set a timeout zstyle for the appropriate (slow) context, and this
will interrupt the completion when the timer expires if it's possible
to do so.
CAVEAT: On my linux desktop at home, this usually works as expected,
but sometimes wedges zsh in the futex() system call. If this happens
you are dead in the water and likely have to kill -9 the whole shell
from another terminal. This is probably highly kernel-specific and
might never happen to you, but you have been warned; this code is
offered without warranty.
# --- 8< --- 8<---
_timeout() {
local timeout
zstyle -s ":completion:${curcontext}:" timeout timeout || return 1
# Dirty trick: By unsetting localtraps, we can
# push this trap up into our caller's context
setopt localoptions nomonitor nolocaltraps
trap '
zle -M "Killed by signal in ${funcstack[1]}";
zle -R; return 130' INT QUIT
# Background job to kill ourself after 10 seconds
{ sleep $timeout; kill -INT $$; exit 0 } &
# Cleanup routine to remove background job, eval for $!
eval "
_timeout_end() {
unfunction _timeout_end
kill $! 2>/dev/null
return 0
}"
comppostfuncs+=(_timeout_end)
# This function adds no completions, so it must not return 0
return 1
}
# Tweak this style as needed
zstyle ':completion:*' completer _oldlist _timeout _complete _ignored
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2014-01-26 7:51 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-26 7:51 Timing out a completion, a different tack Bart Schaefer
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).