From 771b059a526effbddb895fb041e30b3a5e038b48 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Wed, 3 Aug 2011 09:36:49 +0000 Subject: 29635: Improve _complete_debug syntax and handling of fd's --- Completion/Base/Widget/_complete_debug | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'Completion/Base') 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 -- cgit 1.4.1