Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] zed fails with setopt nounset unless option -x is given
- X-seq: zsh-workers 50286
- From: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- To: Risto Laitinen <risto.laitinen@xxxxxxxxx>, zsh-workers@xxxxxxx
- Subject: Re: [PATCH] zed fails with setopt nounset unless option -x is given
- Date: Wed, 25 May 2022 10:48:46 +0100 (BST)
- Archived-at: <https://zsh.org/workers/50286>
- Importance: Medium
- In-reply-to: <641523655.251203.1653056242563@mail2.virginmedia.com>
- List-id: <zsh-workers.zsh.org>
- References: <CAA-Ti-jiCVGAGF6XMi2axwcwkkHrCGzyvh9Biaf-d=qT443pLg@mail.gmail.com> <641523655.251203.1653056242563@mail2.virginmedia.com>
> On 20 May 2022 at 15:17 Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx> wrote:
>
>
> > On 20 May 2022 at 15:06 Risto Laitinen <risto.laitinen@xxxxxxxxx> wrote:
> > % zsh-5.9 -f
> > % autoload zed
> > % setopt nounset
> > % zed a.txt
> > zed:21: opts[-x]: parameter not set
> > %
>
> Looks straightforward.
This is a little better (it doesn't take account of the point Bart
noted). The option handler will return on a bad argument, so actually
the internal handling is now redundant.
pws
diff --git a/Functions/Misc/zed b/Functions/Misc/zed
index 7d0d590db..bb075512c 100644
--- a/Functions/Misc/zed
+++ b/Functions/Misc/zed
@@ -14,15 +14,17 @@ local var opts zed_file_name
integer TMOUT=0 okargs=1 fun hist bind
local -a expand
-zparseopts -D -A opts f h b x:
+zparseopts -D -A opts f h b x: || return 1
fun=$+opts[-f]
hist=$+opts[-h]
bind=$+opts[-b]
-if [[ $opts[-x] == <-> ]]; then
- expand=(-x $opts[-x])
-elif (( $+opts[-x] )); then
- print -r "Integer expected after -x: $opts[-x]" >&2
- return 1
+if (( $+opts[-x] )); then
+ if [[ $opts[-x] == <-> ]]; then
+ expand=(-x $opts[-x])
+ else
+ print -r "Integer expected after -x: $opts[-x]" >&2
+ return 1
+ fi
fi
[[ $0 = fned ]] && fun=1
Messages sorted by:
Reverse Date,
Date,
Thread,
Author