On 4/9/21 4:49 PM, Daniel Shahaf wrote:
This still discards pushd's exit code if it's *non*-zero.
ACK
Yet another variant: pd() case $+1 in (0) popd;; (1) pushd "$1";; esac
Why use "$+1"? I would have thought to use "$#" instead.
Or if golfing: pd()$# $1;0()popd;1()pushd $1
I feel like this is going outside the box. If I'm interpreting it correctly, it's actually defining three functions; pd, 0, and 1, each of which do a teeny tiny piece / sub-function. Wherein pd calls either 0 or 1 + first argument.
I'll give credit for it. But it's not what I originally thought it was going to be. I was naively thinking that it was going to be some alternate syntax for a case statement. That's the effect you get, but not the method.
Aside: If I was going to do this, I'd probably protect the sub-functions so they don't get clobbered:
% functions pd pd () { pd$# $1 } % functions pd0 pd0 () { popd } % functions pd1 pd1 () { pushd $1 } Also, a bug: Passing more than one argument fails.I do play Vim golf. But I've learned that compacting things as tight as possible can make them more difficult to understand ~> maintain in the future. A la. Perl becoming what seems like line noise. So my golfing tends to be interactive Vim and everything else, especially when explaining / teaching something new to someone, is fully expanded.
-- Grant. . . . unix || die
Attachment:
smime.p7s
Description: S/MIME Cryptographic Signature