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
This commit is contained in:
Sean Dague 2016-03-21 17:00:51 -04:00
parent 0a2a7ae847
commit 646085d701
4 changed files with 42 additions and 7 deletions

View File

@ -30,6 +30,19 @@ function function_exists {
declare -f -F $1 > /dev/null 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. # Retrieve an image from a URL and upload into Glance.
# Uses the following variables: # Uses the following variables:
# #

16
stackrc
View File

@ -14,9 +14,6 @@ unset LANGUAGE
LC_ALL=C LC_ALL=C
export LC_ALL export LC_ALL
# Make tracing more educational
export PS4='+ ${BASH_SOURCE:-}:${FUNCNAME[0]:-}:L${LINENO:-}: '
# Find the other rc files # Find the other rc files
RC_DIR=$(cd $(dirname "${BASH_SOURCE:-$0}") && pwd) RC_DIR=$(cd $(dirname "${BASH_SOURCE:-$0}") && pwd)
@ -132,6 +129,16 @@ elif [[ -f $RC_DIR/.localrc.auto ]]; then
source $RC_DIR/.localrc.auto source $RC_DIR/.localrc.auto
fi 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 # Configure Identity API version: 2.0, 3
IDENTITY_API_VERSION=${IDENTITY_API_VERSION:-2.0} IDENTITY_API_VERSION=${IDENTITY_API_VERSION:-2.0}
@ -785,9 +792,6 @@ SYSLOG=$(trueorfalse False SYSLOG)
SYSLOG_HOST=${SYSLOG_HOST:-$HOST_IP} SYSLOG_HOST=${SYSLOG_HOST:-$HOST_IP}
SYSLOG_PORT=${SYSLOG_PORT:-516} 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=<number>`` to limit the history depth of the git clone # Set global ``GIT_DEPTH=<number>`` to limit the history depth of the git clone
# Set to 0 to disable shallow cloning # Set to 0 to disable shallow cloning
GIT_DEPTH=${GIT_DEPTH:-0} GIT_DEPTH=${GIT_DEPTH:-0}

View File

@ -7,6 +7,22 @@
# Warning: This script just for development purposes # Warning: This script just for development purposes
set -o errexit 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 set -o xtrace
ACCOUNT_DIR=./accrc ACCOUNT_DIR=./accrc

View File

@ -11,7 +11,6 @@
# - if USE_PYTHON3=True, PYTHON3_VERSION refers to a version already installed # - if USE_PYTHON3=True, PYTHON3_VERSION refers to a version already installed
set -o errexit set -o errexit
set -o xtrace
# Keep track of the current directory # Keep track of the current directory
TOOLS_DIR=$(cd $(dirname "$0") && pwd) TOOLS_DIR=$(cd $(dirname "$0") && pwd)
@ -23,6 +22,9 @@ cd $TOP_DIR
# Import common functions # Import common functions
source $TOP_DIR/stackrc source $TOP_DIR/stackrc
# don't start tracing until after we've sourced the world
set -o xtrace
FILES=$TOP_DIR/files FILES=$TOP_DIR/files
PIP_GET_PIP_URL=https://bootstrap.pypa.io/get-pip.py PIP_GET_PIP_URL=https://bootstrap.pypa.io/get-pip.py