From 646085d701049004f9b2bcdc38610f3e87579cda Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Mon, 21 Mar 2016 17:00:51 -0400 Subject: [PATCH] Add colorful PS4 PS4 can include functions, so when running in the LOG_COLORS=True mode provide a grey function line so that it's easier to visually distinguish the content from the location. Also make it so the main prompt chunks off all the common path, which means we can printf to 40 characters and have a pretty reasonable and readable PS4. Change-Id: I4a10a49db97d413349bcfceeb8c4164936fbcc40 --- functions | 13 +++++++++++++ stackrc | 16 ++++++++++------ tools/create_userrc.sh | 16 ++++++++++++++++ tools/install_pip.sh | 4 +++- 4 files changed, 42 insertions(+), 7 deletions(-) diff --git a/functions b/functions index 5730b6c894..1bfb8a5078 100644 --- a/functions +++ b/functions @@ -30,6 +30,19 @@ function function_exists { declare -f -F $1 > /dev/null } +# short_source prints out the current location of the caller in a way +# that strips redundant directories. This is useful for PS4 usage. +function short_source { + saveIFS=$IFS + IFS=" " + called=($(caller 0)) + IFS=$saveIFS + file=${called[2]} + file=${file#$RC_DIR/} + printf "%-40s " "$file:${called[1]}:${called[0]}" +} + + # Retrieve an image from a URL and upload into Glance. # Uses the following variables: # diff --git a/stackrc b/stackrc index 74d507cfa2..f606bbbd8f 100644 --- a/stackrc +++ b/stackrc @@ -14,9 +14,6 @@ unset LANGUAGE LC_ALL=C export LC_ALL -# Make tracing more educational -export PS4='+ ${BASH_SOURCE:-}:${FUNCNAME[0]:-}:L${LINENO:-}: ' - # Find the other rc files RC_DIR=$(cd $(dirname "${BASH_SOURCE:-$0}") && pwd) @@ -132,6 +129,16 @@ elif [[ -f $RC_DIR/.localrc.auto ]]; then source $RC_DIR/.localrc.auto fi +# Use color for logging output (only available if syslog is not used) +LOG_COLOR=$(trueorfalse True LOG_COLOR) + +# Make tracing more educational +if [[ "$LOG_COLOR" == "True" ]]; then + export PS4='+\[$(tput setaf 242)\]$(short_source)\[$(tput sgr0)\] ' +else + export PS4='+ $(short_source): ' +fi + # Configure Identity API version: 2.0, 3 IDENTITY_API_VERSION=${IDENTITY_API_VERSION:-2.0} @@ -785,9 +792,6 @@ SYSLOG=$(trueorfalse False SYSLOG) SYSLOG_HOST=${SYSLOG_HOST:-$HOST_IP} SYSLOG_PORT=${SYSLOG_PORT:-516} -# Use color for logging output (only available if syslog is not used) -LOG_COLOR=$(trueorfalse True LOG_COLOR) - # Set global ``GIT_DEPTH=`` to limit the history depth of the git clone # Set to 0 to disable shallow cloning GIT_DEPTH=${GIT_DEPTH:-0} diff --git a/tools/create_userrc.sh b/tools/create_userrc.sh index 3325c5e586..a7278e47b3 100755 --- a/tools/create_userrc.sh +++ b/tools/create_userrc.sh @@ -7,6 +7,22 @@ # Warning: This script just for development purposes set -o errexit + +# short_source prints out the current location of the caller in a way +# that strips redundant directories. This is useful for PS4 +# usage. Needed before we start tracing due to how we set +# PS4. Normally we'd pick this up from stackrc, but that's not sourced +# here. +function short_source { + saveIFS=$IFS + IFS=" " + called=($(caller 0)) + IFS=$saveIFS + file=${called[2]} + file=${file#$RC_DIR/} + printf "%-40s " "$file:${called[1]}:${called[0]}" +} + set -o xtrace ACCOUNT_DIR=./accrc diff --git a/tools/install_pip.sh b/tools/install_pip.sh index 2a9d813eac..87660a677c 100755 --- a/tools/install_pip.sh +++ b/tools/install_pip.sh @@ -11,7 +11,6 @@ # - if USE_PYTHON3=True, PYTHON3_VERSION refers to a version already installed set -o errexit -set -o xtrace # Keep track of the current directory TOOLS_DIR=$(cd $(dirname "$0") && pwd) @@ -23,6 +22,9 @@ cd $TOP_DIR # Import common functions source $TOP_DIR/stackrc +# don't start tracing until after we've sourced the world +set -o xtrace + FILES=$TOP_DIR/files PIP_GET_PIP_URL=https://bootstrap.pypa.io/get-pip.py