* [PATCH] Add -- to the `functions' builtin calls
@ 2015-10-27 16:22 Eric Cook
2015-10-27 17:54 ` [PATCH v2] " Eric Cook
0 siblings, 1 reply; 4+ messages in thread
From: Eric Cook @ 2015-10-27 16:22 UTC (permalink / raw)
To: zsh-workers
Reported on IRC:
% autoload zed; zed -f -- "-zgen-prezto-load"
zed:83: bad option: -g
-zgen-prezto-load() {
}
---
Functions/Misc/zed | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Functions/Misc/zed b/Functions/Misc/zed
index 010b69b..6628b13 100644
--- a/Functions/Misc/zed
+++ b/Functions/Misc/zed
@@ -80,10 +80,10 @@ fi
setopt localoptions nobanghist
if ((fun)) then
- var="$(functions $expand $1)"
+ var="$(functions $expand -- $1)"
# If function is undefined but autoloadable, load it
if [[ $var = *\#\ undefined* ]] then
- var="$(autoload +X $1; functions $1)"
+ var="$(autoload +X $1; functions -- $1)"
elif [[ -z $var ]] then
var="$1() {
}"
--
2.6.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] Add -- to the `functions' builtin calls
2015-10-27 16:22 [PATCH] Add -- to the `functions' builtin calls Eric Cook
@ 2015-10-27 17:54 ` Eric Cook
2015-10-28 2:54 ` [PATCH] zed: fix argument parsing Eric Cook
0 siblings, 1 reply; 4+ messages in thread
From: Eric Cook @ 2015-10-27 17:54 UTC (permalink / raw)
To: zsh-workers
Add -- to autoload too, just in case.
---
Functions/Misc/zed | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Functions/Misc/zed b/Functions/Misc/zed
index 010b69b..1f6042e 100644
--- a/Functions/Misc/zed
+++ b/Functions/Misc/zed
@@ -80,10 +80,10 @@ fi
setopt localoptions nobanghist
if ((fun)) then
- var="$(functions $expand $1)"
+ var="$(functions $expand -- $1)"
# If function is undefined but autoloadable, load it
if [[ $var = *\#\ undefined* ]] then
- var="$(autoload +X $1; functions $1)"
+ var="$(autoload +X -- $1; functions -- $1)"
elif [[ -z $var ]] then
var="$1() {
}"
--
2.6.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] zed: fix argument parsing
2015-10-27 17:54 ` [PATCH v2] " Eric Cook
@ 2015-10-28 2:54 ` Eric Cook
2015-10-31 18:08 ` Eric Cook
0 siblings, 1 reply; 4+ messages in thread
From: Eric Cook @ 2015-10-28 2:54 UTC (permalink / raw)
To: zsh-workers
Also reported in IRC:
% fned +vi-git-applied-string
zed:4: bad option: -v
zed:4: bad option: -i
zed:4: bad option: --
zed:4: bad option: -g
...
This could optionally be fixed by changing getopts "fbx:" to
getopts ":fbx:" so the `unknown options' are silently ignored.
---
Functions/Misc/zed | 31 ++++++++++---------------------
1 file changed, 10 insertions(+), 21 deletions(-)
diff --git a/Functions/Misc/zed b/Functions/Misc/zed
index 1f6042e..ef7f9c1 100644
--- a/Functions/Misc/zed
+++ b/Functions/Misc/zed
@@ -6,31 +6,20 @@
# Use ^X^W to save, ^C to abort.
# Option -f: edit shell functions. (Also if called as fned.)
-local var opt zed_file_name
+local var opts zed_file_name
# We do not want timeout while we are editing a file
integer TMOUT=0 okargs=1 fun bind
local -a expand
-while getopts "fbx:" opt; do
- case $opt in
- (f)
- fun=1
- ;;
-
- (b)
- bind=1
- ;;
-
- (x)
- if [[ $OPTARG != <-> ]]; then
- print -r "Integer expected after -x: $OPTARG" >&2
- return 1
- fi
- expand=(-x $OPTARG)
- ;;
- esac
-done
-shift $(( OPTIND - 1 ))
+zparseopts -D -A opts f b x:
+fun=$+opts[-f]
+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
+fi
[[ $0 = fned ]] && fun=1
(( bind )) && okargs=0
--
2.6.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] zed: fix argument parsing
2015-10-28 2:54 ` [PATCH] zed: fix argument parsing Eric Cook
@ 2015-10-31 18:08 ` Eric Cook
0 siblings, 0 replies; 4+ messages in thread
From: Eric Cook @ 2015-10-31 18:08 UTC (permalink / raw)
To: zsh-workers
On 10/27/2015 10:54 PM, Eric Cook wrote:
> Also reported in IRC:
>
> % fned +vi-git-applied-string
> zed:4: bad option: -v
> zed:4: bad option: -i
> zed:4: bad option: --
> zed:4: bad option: -g
> ...
>
> This could optionally be fixed by changing getopts "fbx:" to
> getopts ":fbx:" so the `unknown options' are silently ignored.
:/ that patch allows `zed -foo' to edit the function `-foo'.
It should error due to unknown options in my opinion.
I think editing files/functions that start with `+' or `-' should require -- to be used.
This patch silents the bad options errors, shown in my first example and zed will show the help message.
To edit the function `+vi-git-applied-string', `--' is needed.
diff --git a/Functions/Misc/zed b/Functions/Misc/zed
index 1f6042e..2c957ba 100644
--- a/Functions/Misc/zed
+++ b/Functions/Misc/zed
@@ -11,7 +11,7 @@ local var opt zed_file_name
integer TMOUT=0 okargs=1 fun bind
local -a expand
-while getopts "fbx:" opt; do
+while getopts ":fbx:" opt; do
case $opt in
(f)
fun=1
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-10-31 18:08 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-27 16:22 [PATCH] Add -- to the `functions' builtin calls Eric Cook
2015-10-27 17:54 ` [PATCH v2] " Eric Cook
2015-10-28 2:54 ` [PATCH] zed: fix argument parsing Eric Cook
2015-10-31 18:08 ` Eric Cook
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).