Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: xargs with zsh function
On Tue, Jan 19, 2021 at 9:52 AM Lawrence Velázquez <vq@xxxxxxxxx> wrote:
>
> > On Jan 19, 2021, at 9:30 AM, Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
> >
> > Anyway I'd like zargs to work within my environment as it is.
>
> To establish a known configuration, zargs resets nearly all zsh options for the duration of its execution. Your function should do likewise.
The latter is always good practice, but it does raise the point that
zargs is less useful if you aren't using something close to zsh mode.
I'm still pondering if there's a better way to do this, but in the meantime ...
(attached to avoid gmail line wrapping)
diff --git a/Functions/Misc/zargs b/Functions/Misc/zargs
index 28ebca78f..49c177fb6 100644
--- a/Functions/Misc/zargs
+++ b/Functions/Misc/zargs
@@ -70,6 +70,15 @@
# this behavior, as do -l/-L, but when -i/-I appear anywhere then -l/-L
# are ignored (forced to 1).
+# First, capture the current setopts as "sticky emulation"
+if zmodload zsh/param
+then
+ emulate zsh -c "_zarun() { options=( ${(j: :kv)options[@]} )"' eval "$@" }'
+else
+ # Warning?
+ _zarun() { eval "$@" }
+fi
+
emulate -L zsh || return 1
local -a opts eof n s l P i
@@ -186,7 +195,7 @@ local execute='
elif (( $opts[(I)-(-verbose|t)] ))
then print -u2 -r -- "$call"
fi
- eval "{
+ _zarun "{
\"\${(@)call}\"
} $bg"'
local ret=0 analyze='
Messages sorted by:
Reverse Date,
Date,
Thread,
Author