about summary refs log tree commit diff
path: root/Completion
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2011-08-03 09:36:49 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2011-08-03 09:36:49 +0000
commit771b059a526effbddb895fb041e30b3a5e038b48 (patch)
tree071e4c5e91689d0525f5e44eac777fbdb37e3caa /Completion
parentd557905eb63f5fa087675e05ba82210c86dde358 (diff)
downloadzsh-771b059a526effbddb895fb041e30b3a5e038b48.tar.gz
zsh-771b059a526effbddb895fb041e30b3a5e038b48.tar.xz
zsh-771b059a526effbddb895fb041e30b3a5e038b48.zip
29635: Improve _complete_debug syntax and handling of fd's
Diffstat (limited to 'Completion')
-rw-r--r--Completion/Base/Widget/_complete_debug26
1 files changed, 16 insertions, 10 deletions
diff --git a/Completion/Base/Widget/_complete_debug b/Completion/Base/Widget/_complete_debug
index 39350b5c5..eff0f8e28 100644
--- a/Completion/Base/Widget/_complete_debug
+++ b/Completion/Base/Widget/_complete_debug
@@ -6,21 +6,27 @@ eval "$_comp_setup"
 local tmp=${TMPPREFIX}${$}${words[1]:t}$[++_debug_count]
 local pager w="${(qq)words}"
 
-exec 3>&-	# Too bad if somebody else is using it ...
-[[ -t 2 ]] && { exec 3>&2 2>| $tmp ; trap 'exec 2>&3 3>&-' EXIT INT }
+integer debug_fd=-1
+{
+  if [[ -t 2 ]]; then
+    exec {debug_fd}>&2 2>| $tmp
+  fi
 
-setopt xtrace
-: $ZSH_NAME $ZSH_VERSION
-${1:-_main_complete}
-integer ret=$?
-unsetopt xtrace
+  setopt xtrace
+  : $ZSH_NAME $ZSH_VERSION
+  ${1:-_main_complete}
+  integer ret=$?
+  unsetopt xtrace
 
-[[ -t 3 ]] && {
+  if (( debug_fd != -1 )); then
     zstyle -s ':completion:complete-debug::::' pager pager
     print -sR "${pager:-${PAGER:-${VISUAL:-${EDITOR:-more}}}} ${(q)tmp} ;: $w"
     _message -r "Trace output left in $tmp (up-history to view)"
-    [[ $compstate[nmatches] -le 1 && $compstate[list] != *force* ]] &&
+    if [[ $compstate[nmatches] -le 1 && $compstate[list] != *force* ]]; then
         compstate[list]='list force messages'
+    fi
+  fi
+} always {
+  (( debug_fd != -1 )) && exec 2>&$debug_fd {debug_fd}>&-
 }
-
 return ret