Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [PATCH] zed: fix argument parsing



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




Messages sorted by: Reverse Date, Date, Thread, Author