diff --git a/sequencer.sh b/sequencer.sh index 0694d03..1747aac 100755 --- a/sequencer.sh +++ b/sequencer.sh @@ -72,6 +72,10 @@ set -o pipefail _sqr_single=0 readonly _sqr_stepMax=512 _sqr_verbose=0 + # Part of a pipe or output to terminal + _sqr_term=0 && [ -t 1 ] && _sqr_term=1 + readonly _sqr_term + _sqr_colorAlways=0 ## Terminal position _sqr_savePosAlias= ;[ -t 1 ] && _sqr_savePosAlias='\033[1A\033[1C\033[s\033[1B\033[1C' @@ -80,23 +84,24 @@ set -o pipefail _sqr_restorePos= ;[ -t 1 ] && _sqr_restorePos='\033[u' ## Terminal colors - col_black= ; [ -t 1 ] && col_black='\033[0;30m' - col_darkgrey= ; [ -t 1 ] && col_darkgrey='\033[1;30m' - col_red= ; [ -t 1 ] && col_red='\033[0;31m' - col_lightred= ; [ -t 1 ] && col_lightred='\033[1;31m' - col_green= ; [ -t 1 ] && col_green='\033[0;32m' - col_lightgreen= ; [ -t 1 ] && col_lightgreen='\033[1;32m' - col_orange= ; [ -t 1 ] && col_orange='\033[0;33m' - col_yellow= ; [ -t 1 ] && col_yellow='\033[1;33m' - col_blue= ; [ -t 1 ] && col_blue='\033[0;34m' - col_lightblue= ; [ -t 1 ] && col_lightblue='\033[1;34m' - col_purple= ; [ -t 1 ] && col_purple='\033[0;35m' - col_lightpurple= ; [ -t 1 ] && col_lightpurple='\033[1;35m' - col_cyan= ; [ -t 1 ] && col_cyan='\033[0;36m' - col_lightcyan= ; [ -t 1 ] && col_lightcyan='\033[1;36m' - col_lightgray= ; [ -t 1 ] && col_lightgray='\033[0;37m' - col_white= ; [ -t 1 ] && col_white='\033[1;37m' - col_off= ;[ -t 1 ] && col_off='\033[0m' # No Color + col_black() { ((_sqr_term)) || ((_sqr_colorAlways)) && printf '%b' '\033[0;30m';} + col_darkgrey() { ((_sqr_term)) || ((_sqr_colorAlways)) && printf '%b' '\033[1;30m';} + col_red() { ((_sqr_term)) || ((_sqr_colorAlways)) && printf '%b' '\033[0;31m';} + col_lightred() { ((_sqr_term)) || ((_sqr_colorAlways)) && printf '%b' '\033[1;31m';} + col_green() { ((_sqr_term)) || ((_sqr_colorAlways)) && printf '%b' '\033[0;32m';} + col_lightgreen() { ((_sqr_term)) || ((_sqr_colorAlways)) && printf '%b' '\033[1;32m';} + col_orange() { ((_sqr_term)) || ((_sqr_colorAlways)) && printf '%b' '\033[0;33m';} + col_yellow() { ((_sqr_term)) || ((_sqr_colorAlways)) && printf '%b' '\033[1;33m';} + col_blue() { ((_sqr_term)) || ((_sqr_colorAlways)) && printf '%b' '\033[0;34m';} + col_lightblue() { ((_sqr_term)) || ((_sqr_colorAlways)) && printf '%b' '\033[1;34m';} + col_purple() { ((_sqr_term)) || ((_sqr_colorAlways)) && printf '%b' '\033[0;35m';} + col_lightpurple() { ((_sqr_term)) || ((_sqr_colorAlways)) && printf '%b' '\033[1;35m';} + col_cyan() { ((_sqr_term)) || ((_sqr_colorAlways)) && printf '%b' '\033[0;36m';} + col_lightcyan() { ((_sqr_term)) || ((_sqr_colorAlways)) && printf '%b' '\033[1;36m';} + col_lightgray() { ((_sqr_term)) || ((_sqr_colorAlways)) && printf '%b' '\033[0;37m';} + col_white() { ((_sqr_term)) || ((_sqr_colorAlways)) && printf '%b' '\033[1;37m';} + ## No Color + col_off() { ((_sqr_term)) || ((_sqr_colorAlways)) && printf '%b' '\033[0m';} } helpSequencer() { @@ -105,6 +110,7 @@ Usage: ${seq_name} [OPTIONS] [STEP NUMBER(s) or ALIAS] [STEP ARGUMENTS] [OPTIONS] --all, -a : Run all steps regardless of continuity + --color : Output color codes also within pipe --config, -c : Open sequence configuration file (also sets -qq) --dry-run, -d : Only print to console what would be done ! Attention - Sequence must support this @@ -169,19 +175,19 @@ sequencer.sh global variables: sequencer.sh build-in functions: USAGE_API - echo -e "${col_green} root${col_off}" + echo -e "$(col_green) root$(col_off)" cat <,<,|). Supporting: dry-run (-d): only print command without execution verbose (-v): print command before execution USAGE_API - echo -e "${col_green} exep \"[COMMAND STRING(s)]\"${col_off}" + echo -e "$(col_green) exep \"[COMMAND STRING(s)]\"$(col_off)" cat < \\'out put.log\\' @@ -261,13 +267,13 @@ USAGE_API - All apostrophes need to be esacped since the command line is given as string. USAGE_API - echo -e "${col_green} escpath ${col_off}" + echo -e "$(col_green) escpath $(col_off)" cat < [TEMPLATE]${col_off}" + echo -e "$(col_green) initSeqConfig [OPTION] [TEMPLATE]$(col_off)" cat < [SOURCE TYPE] ${col_off}" + echo -e "$(col_green) addConf [SOURCE TYPE] $(col_off)" cat <) to a destination file. If the CONFIGFILE exists, a backup (name_%Y%m%d-%H%M%S.bck) is saved at the same location. @@ -301,13 +307,13 @@ USAGE_API Target file to be created or modified. USAGE_API - echo -e "${col_green} step ${col_off}" + echo -e "$(col_green) step $(col_off)" cat < [DESCRIPTION]${col_off}" + echo -e "$(col_green) endIfEmpty [DESCRIPTION]$(col_off)" cat < : Name without \$ [DESCRIPTION] : Additional text for error output USAGE_API - echo -e "${col_green} saveReturn [ERRORCODE]${col_off}" + echo -e "$(col_green) saveReturn [ERRORCODE]$(col_off)" cat < show help displayHelp fi # Assume starting at one for interactive mode toStart=( "1" ) - elif [ $quickStartOne -ne 0 ] ; then + elif (( quickStartOne )) ; then emptyCall=0 toStart=( "1" ) seq_args=( "$@" ) @@ -1635,7 +1642,7 @@ sqr::main() { else error "No configuration file available" fi - [ ${emptyCall} -ne 0 ] && exit 0 + (( emptyCall )) && exit 0 fi if checkStep "${toStart[0]}" >/dev/null 2>&1 ; then @@ -1658,7 +1665,7 @@ sqr::main() { fi # check if more than one step is given and select execution mode - if [ ${_sqr_single} -ne 0 ] ; then + if (( _sqr_single )) ; then selection "${toStart[0]}" elif [ "${#toStart[@]}" -gt "1" ]; then selection "${toStart[@]}"