first commit
This commit is contained in:
commit
0610f4aeab
130 changed files with 9897 additions and 0 deletions
42
fn/-z4h-run-process-tree
Normal file
42
fn/-z4h-run-process-tree
Normal file
|
@ -0,0 +1,42 @@
|
|||
#!/usr/bin/env zsh
|
||||
#
|
||||
# Based on https://github.com/romkatv/run-process-tree but without
|
||||
# the preservation of options, patterns, etc.
|
||||
|
||||
emulate -L zsh || return
|
||||
setopt monitor traps_async pipe_fail no_unset no_bg_nice || return
|
||||
zmodload zsh/system || return
|
||||
|
||||
local stdout REPLY
|
||||
exec {stdout}>&1 || return
|
||||
{
|
||||
{
|
||||
local -i pipe
|
||||
local sig=(EXIT HUP ILL INT PIPE QUIT TERM ZERR)
|
||||
local trap=(trap "trap - $sig; kill -- -$sysparams[pid]" $sig)
|
||||
|
||||
exec {pipe}>&1 1>&$stdout || return
|
||||
$trap
|
||||
|
||||
{
|
||||
$trap
|
||||
while command sleep 1 && print -u $pipe .; do; done
|
||||
} 2>/dev/null &
|
||||
local -i watchdog=$!
|
||||
|
||||
{
|
||||
trap - ZERR
|
||||
exec {pipe}>&- || return
|
||||
() { "$@" } "$@"
|
||||
} &
|
||||
local -i ret
|
||||
wait $! || ret=$?
|
||||
|
||||
trap "exit $ret" TERM
|
||||
kill $watchdog || return
|
||||
wait $watchdog || return
|
||||
return ret
|
||||
} | while read; do; done || return
|
||||
} always {
|
||||
exec {stdout}>&-
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue