From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh Users <zsh-users@sunsite.dk>
Subject: Re: Honoring a command
Date: Mon, 5 Apr 2004 01:09:32 +0000 [thread overview]
Message-ID: <1040405010932.ZM22507@candle.brasslantern.com> (raw)
In-Reply-To: <20040404111615.GI27014@DervishD>
On Apr 4, 1:16pm, DervishD wrote:
}
} The number of beers I owe you is growing dangerously ;)
Especially considering that I rarely drink beer. Send me a six-pack of
some unusual Spanish soft drink, or something. ;-}
} alias scriptinit=$'emulate -L zsh ; trap \'return $LINENO\' ZERR'
An interesting tidbit I just noticed -- if you read the script with the
"source" or "." commands, $LINENO is reset to 1 when the trap runs, so
you don't get as useful a return value.
} The problem is that it doesn't work with the above usage of
} verbosely_watch, because the trap is never run due to the OR list. I
} must replace:
}
} { whatever.command 2> /dev/null || print "Error message"}
}
} by:
}
} { whatever.command 2> /dev/null || print "Error message";false}
Actually that won't work either, because that _always_ executes "false".
I think you meant
{ whatever.command 2> /dev/null || { print "Error message";false } }
} but then 'verbosely_watch' has no purpose at all!
You could write another little function:
verbosely_fail() {
local ret=$?
[[ -p /dev/fd/1 ]] && print "$*"
return ret
}
Now this works:
{ whatever.command || verbosely_fail "Error message" } 2>/dev/null |
verbosely_watch "Doing whatever"
If you DON'T pipe to verbosely_watch, then verbosely_fail is silent and the
ZERR trap returns the line number as $?. (Even if you do pipe it, the line
number is stored in $pipestatus[1], which may be useful for other tricks.)
} I think I'd better use 'scriptinit' only for muted
} scripts and verbosely_watch for the rest, using TRAPZERR for the
} error message. Is that a good idea?
That would work as well, but it means the error message is the same for
every command (unless you re-assign it somehow each time).
next prev parent reply other threads:[~2004-04-05 1:09 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-04-01 17:03 DervishD
2004-04-03 21:43 ` Bart Schaefer
2004-04-04 11:16 ` DervishD
2004-04-05 1:09 ` Bart Schaefer [this message]
2004-04-05 9:59 ` DervishD
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1040405010932.ZM22507@candle.brasslantern.com \
--to=schaefer@brasslantern.com \
--cc=zsh-users@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).