Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

How to exit function on a trap (INT)



Hello,
I have an adhoc tests-related autoload-*function* `test-id-as':

https://github.com/zdharma/zplugin/blob/c1fc6d9325f97264ff155210fedd6bebc421b5e4/doc/test-id-as

It's doing `setopt localtraps' and essentially `trap '...; return 0;'
EXIT INT TERM QUIT

The problem: Single Ctrl-C doesn't stop the function, I have to hold
the key combination, see fast sequence of interrupted states of the
trying-to-execute-anyway function, to finally luckily "reach" the exit
of the function, via dense Ctrl-C signaling (result of continuous hold
of Ctrl-C keys).

I have some experience with functions and traps, and I recall I was
successfully exiting functions this way. Should this method work? What
can be wrong?

The actual trap setup is little long, but it simply has `; return 0;'
at the end:

trap '[[ $argv1 != "--keep" ]] && { ZPLGM[PLUGINS_DIR]=$plg_bkp;
ZPLGM[SNIPPETS_DIR]=$snp_bkp; } || { print; print "Kept
${ZPLGM[PLUGINS_DIR]} :: ${ZPLGM[SNIPPETS_DIR]}"; }; return 0;' EXIT
INT TERM QUIT

-- 
Sebastian Gniazdowski
News: https://twitter.com/ZdharmaI
IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin
Blog: http://zdharma.org



Messages sorted by: Reverse Date, Date, Thread, Author