Patchwork zsh_completion: hide commands' stderr when parsing their output

login
register
mail settings
Submitter Nikolaj Sjujskij
Date April 17, 2013, 6:41 a.m.
Message ID <e86de327d1a634f45455.1366180876@VerkDatorn.npdb>
Download mbox | patch
Permalink /patch/1376/
State Rejected, archived
Headers show

Comments

Nikolaj Sjujskij - April 17, 2013, 6:41 a.m.
# HG changeset patch
# User Nikolaj Sjujskij <sterkrig@myopera.com>
# Date 1365878437 -14400
#      Sat Apr 13 22:40:37 2013 +0400
# Node ID e86de327d1a634f454556a34170826b1cad58f11
# Parent  12acbea17625a1441503418f7f2f49aa3825cf2f
zsh_completion: hide commands' stderr when parsing their output

If anything is wrong with hg command used, its stderr output should be silenced
rather than mangle command line.

Change merged back from zsh.git repo, which diverged a bit since when in 2009
Brendan Cully got this file (as it was in 7f349588665f) included there. Command
invocations added to our `zsh_completion` since 2009 updated as well.
Brendan Cully - April 17, 2013, 6:50 a.m.
On Wednesday, 17 April 2013 at 10:41, Nikolaj Sjujskij wrote:
> # HG changeset patch
> # User Nikolaj Sjujskij <sterkrig@myopera.com>
> # Date 1365878437 -14400
> #      Sat Apr 13 22:40:37 2013 +0400
> # Node ID e86de327d1a634f454556a34170826b1cad58f11
> # Parent  12acbea17625a1441503418f7f2f49aa3825cf2f
> zsh_completion: hide commands' stderr when parsing their output
> 
> If anything is wrong with hg command used, its stderr output should be silenced
> rather than mangle command line.
> 
> Change merged back from zsh.git repo, which diverged a bit since when in 2009
> Brendan Cully got this file (as it was in 7f349588665f) included there. Command
> invocations added to our `zsh_completion` since 2009 updated as well.

Thanks. I'm a little confused though, since _hg_cmd is defined thusly:

_hg_cmd() {
  _call_program hg HGPLAIN=1 hg "$_hg_cmd_globals[@]" "$@" 2> /dev/null
}

Shouldn't that already be suppressing stderr?

Patch

diff --git a/contrib/zsh_completion b/contrib/zsh_completion
--- a/contrib/zsh_completion
+++ b/contrib/zsh_completion
@@ -163,14 +163,14 @@ 
 }
 
 _hg_labels() {
-  labels=("${(f)$(_hg_cmd debuglabelcomplete)}")
+  labels=("${(f)$(_hg_cmd debuglabelcomplete 2> /dev/null)}")
   (( $#labels )) && _describe -t labels 'labels' labels
 }
 
 _hg_bookmarks() {
   typeset -a bookmark bookmarks
 
-  _hg_cmd bookmarks | while read -A bookmark
+  _hg_cmd bookmarks 2> /dev/null | while read -A bookmark
   do
     if test -z ${bookmark[-1]:#[0-9]*}
     then
@@ -184,7 +184,7 @@ 
   typeset -a branches
   local branch
 
-  _hg_cmd branches | while read branch
+  _hg_cmd branches 2> /dev/null | while read branch
   do
     branches+=(${branch/ #[0-9]#:*})
   done
@@ -196,16 +196,16 @@ 
   typeset -a heads
   local myrev
 
-  heads=(${(f)"$(_hg_cmd heads --template '{rev}:{branch}\\n')"})
+  heads=(${(f)"$(_hg_cmd heads --template '{rev}:{branch}\\n' 2> /dev/null)"})
   # exclude own revision
-  myrev=$(_hg_cmd log -r . --template '{rev}:{branch}\\n')
+  myrev=$(_hg_cmd log -r . --template '{rev}:{branch}\\n') 2> /dev/null
   heads=(${heads:#$myrev})
 
   (( $#heads )) && _describe -t heads 'heads' heads
 
-  branches=(${(f)"$(_hg_cmd heads --template '{branch}\\n')"})
+  branches=(${(f)"$(_hg_cmd heads --template '{branch}\\n' 2> /dev/null)"})
   # exclude own revision
-  myrev=$(_hg_cmd log -r . --template '{branch}\\n')
+  myrev=$(_hg_cmd log -r . --template '{branch}\\n' 2> /dev/null)
   branches=(${branches:#$myrev})
 
   (( $#branches )) && _describe -t branches 'branches' branches
@@ -230,7 +230,7 @@ 
 
 _hg_status() {
   [[ -d $PREFIX ]] || PREFIX=$PREFIX:h
-  status_files=(${(ps:\0:)"$(_hg_cmd status -0n$1 ./$PREFIX)"})
+  status_files=(${(ps:\0:)"$(_hg_cmd status -0n$1 ./$PREFIX 2>/dev/null)"})
 }
 
 _hg_unknown() {
@@ -256,7 +256,7 @@ 
 
   [[ -d $PREFIX ]] || PREFIX=$PREFIX:h
 
-  _hg_cmd resolve -l ./$PREFIX | while read rstate rpath
+  _hg_cmd resolve -l ./$PREFIX 2> /dev/null | while read rstate rpath
   do
     [[ $rstate == 'R' ]] && resolved_files+=($rpath)
     [[ $rstate == 'U' ]] && unresolved_files+=($rpath)
@@ -300,7 +300,7 @@ 
       compset -P '*/'
       if _cache_invalid "$cacheid" || ! _retrieve_cache "$cacheid"
       then
-        remdirs=(${${(M)${(f)"$(_call_program files ssh -a -x $host ls -1FL "${(q)rempath}")"}##*/}%/})
+        remdirs=(${${(M)${(f)"$(_call_program files ssh -a -x $host ls -1FL "${(q)rempath}" 2> /dev/null)"}##*/}%/})
         _store_cache "$cacheid" remdirs
       fi
       _describe -t directories 'remote directory' remdirs -S/
@@ -338,7 +338,7 @@ 
 
 _hg_paths() {
   typeset -a paths pnames
-  _hg_cmd paths | while read -A pnames
+  _hg_cmd paths 2> /dev/null | while read -A pnames
   do
     paths+=($pnames[1])
   done
@@ -390,8 +390,8 @@ 
 )
 
 _hg_pat_opts=(
-  '*'{-I+,--include}'[include names matching the given patterns]:dir:_files -W $(_hg_cmd root) -/'
-  '*'{-X+,--exclude}'[exclude names matching the given patterns]:dir:_files -W $(_hg_cmd root) -/')
+  '*'{-I+,--include}'[include names matching the given patterns]:dir:_files -W $(_hg_cmd root 2> /dev/null) -/'
+  '*'{-X+,--exclude}'[exclude names matching the given patterns]:dir:_files -W $(_hg_cmd root 2> /dev/null) -/')
 
 _hg_clone_opts=(
   $_hg_remote_opts
@@ -935,13 +935,13 @@ 
 # MQ
 _hg_qseries() {
   typeset -a patches
-  patches=(${(f)"$(_hg_cmd qseries)"})
+  patches=(${(f)"$(_hg_cmd qseries 2> /dev/null)"})
   (( $#patches )) && _describe -t hg-patches 'patches' patches
 }
 
 _hg_qapplied() {
   typeset -a patches
-  patches=(${(f)"$(_hg_cmd qapplied)"})
+  patches=(${(f)"$(_hg_cmd qapplied 2> /dev/null)"})
   if (( $#patches ))
   then
     patches+=(qbase qtip)
@@ -951,15 +951,15 @@ 
 
 _hg_qunapplied() {
   typeset -a patches
-  patches=(${(f)"$(_hg_cmd qunapplied)"})
+  patches=(${(f)"$(_hg_cmd qunapplied 2> /dev/null)"})
   (( $#patches )) && _describe -t hg-unapplied-patches 'unapplied patches' patches
 }
 
 # unapplied, including guarded patches
 _hg_qdeletable() {
   typeset -a unapplied
-  unapplied=(${(f)"$(_hg_cmd qseries)"})
-  for p in $(_hg_cmd qapplied)
+  unapplied=(${(f)"$(_hg_cmd qseries 2> /dev/null)"})
+  for p in $(_hg_cmd qapplied 2> /dev/null)
   do
     unapplied=(${unapplied:#$p})
   done
@@ -971,7 +971,7 @@ 
   typeset -a guards
   local guard
   compset -P "+|-"
-  _hg_cmd qselect -s | while read guard
+  _hg_cmd qselect -s 2> /dev/null | while read guard
   do
     guards+=(${guard#(+|-)})
   done