Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: stderr from _call_program (Re: rsync --progress stops completion)
- X-seq: zsh-workers 33223
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Re: stderr from _call_program (Re: rsync --progress stops completion)
- Date: Tue, 23 Sep 2014 09:08:46 -0700
- In-reply-to: <11100.1411483304@thecus.kiddle.eu>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <lv9jav$8l6$1@ger.gmane.org> <2002755.9ryFYYVtTN@note> <5418786F.8030001@thregr.org> <140916175124.ZM5742@torch.brasslantern.com> <54194198.2010607@thregr.org> <140917085133.ZM6725@torch.brasslantern.com> <541AA918.8060503@thregr.org> <140918093602.ZM7963@torch.brasslantern.com> <140918190130.ZM8366@torch.brasslantern.com> <9603.1411126819@thecus.kiddle.eu> <140920174851.ZM5095@torch.brasslantern.com> <11100.1411483304@thecus.kiddle.eu>
On Sep 23, 4:41pm, Oliver Kiddle wrote:
}
} I think we can safely append 2>/dev/null to the eval. If the command
} (either from a zstyle preference or the function) uses 2>&1, output
} should be captured:
} % eval 'unknown 2>&1' 2>/dev/null
} zsh: command not found: unknown
Right, in the 2>&1 case you'll get (zsh: command not found: unknown) as
the list of completions, which isn't ideal either.
The body of _call_program is just one big "if ... fi" with several
"eval"s; I propose simply redirecting the stderr of that entire thing.
} Another possibility along similar lines would be to install a
} command_not_found_handler function for the duration of the completion
} system. Avoiding command not found errors is the main (but not only)
} reason for redirecting stderr with _call_program.
Sadly this doesn't work either. Aside from it being difficult to save
and restore the user's command_not_found handler (tricks that used to
mostly work for this now break for functions that use sticky options),
the actual use of _call_program is almost always inside $(...) or as
the left side of a pipe to "while read ...", so the not-found handler
can't do anything useful like calling _message -- it can only print a
set of dummy completions, which doesn't really help.
The only cases of _call_program I've found that aren't executed in a
subshell are in guard functions in _git, and two calls in _texinfo that
look like mistakes to me.
} We should also consider _complete_debug, perhaps directing stderr to the
} log file instead of /dev/null.
Good thought. It's amazingly difficult to do a conditional redirection.
diff --git a/Completion/Base/Utility/_call_program b/Completion/Base/Utility/_call_program
index b038a80..b657648 100644
--- a/Completion/Base/Utility/_call_program
+++ b/Completion/Base/Utility/_call_program
@@ -1,6 +1,13 @@
#autoload +X
-local tmp
+local tmp err_fd=-1
+
+if (( ${debug_fd:--1} > 2 ))
+then exec {err_fd}>&2 # debug_fd is saved stderr, 2 is log file
+else exec {err_fd}>/dev/null
+fi
+
+{ # Begin "always" block
if zstyle -s ":completion:${curcontext}:${1}" command tmp; then
if [[ "$tmp" = -* ]]; then
@@ -10,4 +17,10 @@ if zstyle -s ":completion:${curcontext}:${1}" command tmp; then
fi
else
eval "$argv[2,-1]"
-fi
+fi 2>&$err_fd
+
+} always {
+
+exec {err_fd}>&-
+
+}
diff --git a/Completion/Unix/Command/_texinfo b/Completion/Unix/Command/_texinfo
index 12d964e..025b7b9 100644
--- a/Completion/Unix/Command/_texinfo
+++ b/Completion/Unix/Command/_texinfo
@@ -6,7 +6,7 @@ local -a info
case $service in
info)
- info=( _call_program info ${words[1]} )
+ info=( $(_call_program info ${words[1]}) )
_arguments -C -s \
'(: -)--apropos=[look up string in indices]:search string: ' \
'(-f --file)'{\*-d,\*--directory=}'[add directory to infopath]:info dir:_files -/' \
@@ -140,7 +140,7 @@ case $service in
'-file:info file:_files -g "*.info(|.gz|.bz2)(-.)"' \
'-node:info node:->item' \
'*::menu items:->item' && ret=0
- info=( _call_program info info ${(kv)opt_args[(I)-file]/-file/-f} )
+ info=( $(_call_program info info ${(kv)opt_args[(I)-file]/-file/-f}) )
;;
esac
Messages sorted by:
Reverse Date,
Date,
Thread,
Author