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

[PATCH] _arguments --: correctly handle optional argument in help text



Help text (output of 'cmd --help') can include a line like

    --log[=FILE]    log file (default stderr)

Here [=FILE] indicates the argument is optional.

But with the current _arguments:

% cmd () { echo "\t--add\n\t--del\n\t--log[=FILE]  log file" }
% compdef _gnu_generic cmd
% cmd --log -<TAB>
No match for: `file'

Since the argument to --log is optional, options --add and --del
should be offered here.

This is due to the lines 135-136 of _arguments. The comments say the
lines are for handling the following help text of fetchmail command

    --[fetch]all    maybe some explanation here

but the pattern (*)\[(*)\](*) used there also matches
--log[=FILE], and it is converted into --log=FILE and --log.

In the patch below, I used more restrictive pattern
--\[(*)\](*) so that it only matches [...] just after --.


_BUT_, there is already a completion function for fetchmail
(Completion/Unix/Command/_fetchmail), although it is not updated
at least since 2001.

I kept the lines 135-6 (with fix) in case some other command(s) use
--[xxx]yyy in help texts, but if it's better to remove the lines
rather than fixing them, please let me know.




diff --git a/Completion/Base/Utility/_arguments b/Completion/Base/Utility/_arguments
index 3f1b39304..cab7c929e 100644
--- a/Completion/Base/Utility/_arguments
+++ b/Completion/Base/Utility/_arguments
@@ -132,8 +132,8 @@ if (( long )); then
 	 # variant syntax seen in fetchmail:
 	 # --[fetch]all  means --fetchall or --all.
 	 # maybe needs to be more general
-	 if [[ $start = (#b)(*)\[(*)\](*) ]]; then
-	   tmp+=("${match[1]}${match[2]}${match[3]}" "${match[1]}${match[3]}")
+	 if [[ $start = (#b)--\[(*)\](*) ]]; then
+	   tmp+=("--${match[1]}${match[2]}" "--${match[2]}")
 	 else
 	   tmp+=($start)
 	 fi









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