From 1697c66240bc9d7b85e50f500ac6704f8e69bf33 Mon Sep 17 00:00:00 2001 From: Hugues Hiegel Date: Thu, 7 Jun 2012 15:25:57 +0200 Subject: [Debug] better debug managment --- 01_Internal.zsh | 6 ++++++ 12_Prompts.zsh | 51 +++++++++++++++++++++------------------------------ 20_Options.zsh | 6 +++--- zshrc | 18 +++++++++++------- 4 files changed, 41 insertions(+), 40 deletions(-) diff --git a/01_Internal.zsh b/01_Internal.zsh index 359c01c..44c4716 100644 --- a/01_Internal.zsh +++ b/01_Internal.zsh @@ -24,6 +24,7 @@ __cmd_exists () __term_title() { + __debug -n " Term title..." # Jobs typeset -A command for word in ${=@} ; command[$#command]=$word @@ -73,6 +74,7 @@ __term_title() ;; esac fi + __debug } __preprint() @@ -105,10 +107,14 @@ __get_gcl_branch () { case $1 in git) + __debug -n " GIT status..." __get_git_branch + __debug ;; hg) + __debug -n " HG status..." __get_hg_branch + __debug ;; *) ;; diff --git a/12_Prompts.zsh b/12_Prompts.zsh index 20a4f94..ab0711b 100644 --- a/12_Prompts.zsh +++ b/12_Prompts.zsh @@ -69,6 +69,7 @@ __hbar() { if [ $COLUMNS != $_COLUMNS_OLD ] then + __debug -n " Horizontal bar..." _COLUMNS_OLD=$COLUMNS unset HBAR HBAR=$C_$_prompt_colors[bar]$_C$T_ @@ -77,6 +78,7 @@ __hbar() HBAR=${HBAR}$_tq_ done HBAR=$HBAR$_T + __debug fi } @@ -122,47 +124,38 @@ __set_prompt_date() end=${${1:+$_tm_}:-$_tl_} # Date - [ "$DEBUG" = "yes" ] && echo -n " Date..." >&2 - DATE=$C_$_prompt_colors[braces]$_C$T_"${begin}"$_T" "$C_$_prompt_colors[date]$_C"%D{%a-%d-%b-%Y %H:%M:%S}"$C_$_prompt_colors[braces]$_C" "$C_$_prompt_colors[bar]$_C$T_"${end}$_tq_"$_T + __debug -n " Date..." + DATE=$C_$_prompt_colors[braces]$_C$T_"${begin}"$_T" "$C_$_date_colors[${1:-normal}]$_C"%D{%a-%d-%b-%Y %H:%M:%S}"$C_$_prompt_colors[braces]$_C" "$C_$_prompt_colors[bar]$_C$T_"${end}$_tq_"$_T DATEEXPAND=$(__expand_text "$DATE") DATESIZE=${#DATEEXPAND} - [ "$DEBUG" = "yes" ] && echo >&2 + __debug } __update_prompt_elements() { - - [ "$DEBUG" = "yes" ] && echo -n " Term title..." >&2 - # Flush the term title __term_title - [ "$DEBUG" = "yes" ] && echo >&2 - __set_prompt_date - - [ "$DEBUG" = "yes" ] && echo -n " Horizontal bar..." >&2 __hbar - [ "$DEBUG" = "yes" ] && echo >&2 - __vcsbranch - } __error_code () { # Error - [ "$DEBUG" = "yes" ] && echo -n " Error code..." >&2 + __debug -n " Error code..." echo ${ERROR:+$C_$_prompt_colors[error]$_C$ERROR} - [ "$DEBUG" = "yes" ] && echo >&2 + __debug } PS1_TASKBAR+=(__error_code) __ssh_gpg_agents () { - [ "$DEBUG" = "yes" ] && echo -n " Agents..." >&2 + __debug -n " Agents..." # GPG/SSH agents AGENTS="" - [ "$DEBUG" = "yes" ] && echo && echo -n " ......SSH" >&2 + __debug + __debug -n " ......SSH" # Check ssh-agent only if the env socket has been set and is accessible if [ -S "$SSH_AUTH_SOCK" ] then @@ -198,7 +191,8 @@ __ssh_gpg_agents () fi fi - [ "$DEBUG" = "yes" ] && echo >&2 && echo -n " ......GPG" >&2 + __debug + __debug -n " ......GPG" GPG_AGENT_PID="$(echo $GPG_AGENT_INFO | cut -d: -f2)" if [ "$GPG_AGENT_PID" != "" -a -e /proc/$GPG_AGENT_PID/cmdline ] then @@ -208,7 +202,7 @@ __ssh_gpg_agents () AGENTS=$AGENTS$C_$_agent_colors[$AGENTCOLOR]$_C${GPG_AGENT_RUNNING:-⚡} fi fi - [ "$DEBUG" = "yes" ] && echo >&2 + __debug echo $AGENTS } @@ -220,18 +214,19 @@ __vcsbranch () # get cvs tag # CVSTAG="" - [ "$DEBUG" = "yes" ] && echo -n " CVS status..." >&2 if [ -d CVS ] then + __debug -n " CVS status..." CVSTAG=$(test -e CVS/Tag && cat CVS/Tag || basename $(cat CVS/Root 2>&- || echo "HEAD") ) CVSTAG=${CVSTAG:+ $C_$_gcl_colors[uptodate]$_C$CVSTAG} + __debug fi if [ -d .svn ] then # get svn status # - [ "$DEBUG" = "yes" ] && echo -n " SVN status..." >&2 + __debug -n " SVN status..." SVNREV=$(LC_ALL=C svn info 2>&- $PWD | awk '/^Revision: / {print $2}') SVNREVSIZE=${#${SVNREV:+ r$SVNREV}} if [ "$SVNREV" != "" ] @@ -243,29 +238,25 @@ __vcsbranch () fi fi SVNREV=${SVNREV:+$C_$_prompt_colors[doubledot]$_C $C_$SVNSTATUS$_C"r"$SVNREV} - [ "$DEBUG" = "yes" ] && echo >&2 + __debug fi # get hg status - [ "$DEBUG" = "yes" ] && echo -n " HG status..." >&2 HGBRANCH=$(__get_gcl_branch hg) [ ! -z "$HGBRANCH" ] && HGBRANCH=" "$HGBRANCH - [ "$DEBUG" = "yes" ] && echo >&2 # get git status # - [ "$DEBUG" = "yes" ] && echo -n " GIT status..." >&2 GITBRANCH=$(__get_gcl_branch git) GITBRANCHSIZE=${#GITBRANCH} [ $GITBRANCHSIZE -gt 0 ] && GITBRANCHSIZE=$(($GITBRANCHSIZE)) - [ "$DEBUG" = "yes" ] && echo >&2 - [ "$DEBUG" = "yes" ] && echo -n " Path..." >&2 + __debug -n " Path..." MY_PATH="%(!.%d.%~)" PATHSIZE=$(print -Pn $MY_PATH) PATHSIZE=${#PATHSIZE} - [ "$DEBUG" = "yes" ] && echo >&2 - [ "$DEBUG" = "yes" ] && echo -n " Resize path / gitbranch..." >&2 + __debug + __debug -n " Resize path / gitbranch..." spaceleft=`__expand_text "%n@%m${DISPLAY:+($DISPLAY)}$COMPILATION $ ls -laCdtrux $DATE"` spaceleft=$(($COLUMNS - ${#spaceleft})) #minimalpathsize=`print -Pn "../%1~"` @@ -297,7 +288,7 @@ __vcsbranch () GITBRANCH=$C_$_prompt_colors[soft_generic]$_C${${GITBRANCH/→/$C_"$(__get_git_status)"$_C}/←/$C_$_prompt_colors[soft_generic]$_C}"$(__get_guilt_series)$C_$color[none]$_C" fi CURDIR="$C_$_prompt_colors[path]$_C%`echo $spaceleft`<..<"$MY_PATH"%<<$C_$color[none]$_C" - [ "$DEBUG" = "yes" ] && echo >&2 + __debug VCSBRANCH=$CVSTAG$SVNREV$GITBRANCH$HGBRANCH diff --git a/20_Options.zsh b/20_Options.zsh index cb25a94..e5c8b40 100644 --- a/20_Options.zsh +++ b/20_Options.zsh @@ -40,16 +40,16 @@ function SetOPTifExists() { # option exists, set it. case "$2" in on) - [ "$DEBUG" = "yes" ] && echo "setopt $option" >&2 + __debug "setopt $option" setopt $option ;; off) - [ "$DEBUG" = "yes" ] && echo "unsetopt $option" >&2 + __debug "unsetopt $option" unsetopt $option ;; esac else - [ "$DEBUG" = "yes" ] && echo "$option not supported by this version of zsh !" >&2 + __debug "$option not supported by this version of zsh !" fi } diff --git a/zshrc b/zshrc index 88b7d35..5061236 100644 --- a/zshrc +++ b/zshrc @@ -45,17 +45,21 @@ KEYCHAIN=~/.keychain/$(hostname)-sh [ -r "${KEYCHAIN}-gpg" ] && source ${KEYCHAIN}-gpg -DEBUG=${DEBUG:-no} +__debug () +{ + [ -n "$DEBUG" ] && echo >&2 $@ +} export USER HOST DOMAIN UID if [ -d $ZDOTDIR ]; then + for script in $ZDOTDIR/??_*.zsh do - [ "$DEBUG" = "yes" ] && echo -n "${${script:t:r}/??_/}... " + __debug -n "${${script:t:r}/??_/}... " source $script - [ "$DEBUG" = "yes" ] && echo + __debug for i in "net:$DOMAIN"\ "host:$HOST"\ @@ -82,15 +86,15 @@ if [ -d $ZDOTDIR ]; then specific_script=${script:h}/$i/${${script:t}/??_/} if test -f $specific_script then - [ "$DEBUG" = "yes" ] && echo -n "$i/${${specific_script:t:r}/??_/}... "; + __debug -n "$i/${${specific_script:t:r}/??_/}... "; source $specific_script - [ "$DEBUG" = "yes" ] && echo + __debug fi if test -f $specific_script.gpg then - [ "$DEBUG" = "yes" ] && echo -n "$i/${${specific_script:t:r}/??_/} [CRYPTED]... "; + __debug -n "$i/${${specific_script:t:r}/??_/} [CRYPTED]... "; eval $(gpg --quiet --decrypt $specific_script.gpg) - [ "$DEBUG" = "yes" ] && echo + __debug fi done done -- cgit v1.2.3