From e384d15d4bf81bce2049d9ea6fd1b3fddebf0d92 Mon Sep 17 00:00:00 2001 From: Anthony Axenov Date: Mon, 10 Jul 2023 10:47:25 +0000 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8=D0=BB(?= =?UTF-8?q?=D0=B0)=20=D0=BD=D0=B0=20'shell/helpers.sh'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shell/helpers.sh | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/shell/helpers.sh b/shell/helpers.sh index 4f4bc4b..0332dc0 100644 --- a/shell/helpers.sh +++ b/shell/helpers.sh @@ -224,8 +224,8 @@ dt() { echo "[$(date +'%H:%M:%S')] " } -ask() { - IFS= read -rp "$(print ${BOLD}${BBLUE}${FWHITE}${IASK}${BRESET}\ ${BOLD}$1 ): " $2 +ask() { + IFS= read -rp "$(print ${BOLD}${BBLUE}${FWHITE}${IASK}${BRESET}\ ${BOLD}$1 ): " $2 } print() { @@ -234,48 +234,48 @@ print() { debug() { if [ "$2" ]; then - print "${DIM}${BOLD}${RESET}${DIM} ${FUNCNAME[1]:-?}():${BASH_LINENO:-?}\t$1 " + print "${DIM}${BOLD}${RESET}${DIM}$(dt)${IDEBUG} ${FUNCNAME[1]:-?}():${BASH_LINENO:-?}\t$1 " >&2 else - print "${DIM}${BOLD}${RESET}${DIM}$1 " + print "${DIM}${BOLD}${RESET}${DIM}$(dt)${IDEBUG} $1 " >&2 fi } var_dump() { - debug "$1 = ${!1}" 0 + debug "$1 = ${!1}" } verbose() { - print "${BOLD}${IVRB}${RESET}${FYELLOW} $1 " + print "${BOLD}$(dt)${IVRB}${RESET}${FYELLOW} $1 " } info() { - print "${BOLD}${FWHITE}${BLBLUE}${IINFO}${RESET}${FWHITE} $1 " + print "${BOLD}$(dt)${FWHITE}${BLBLUE}${IINFO}${RESET}${FWHITE} $1 " } note() { - print "${BOLD}${DIM}${FWHITE}${INOTE}${RESET} $1 " + print "${BOLD}$(dt)${DIM}${FWHITE}${INOTE}${RESET} $1 " } success() { - print "${BOLD}${BGREEN}${FWHITE}${ISUCCESS}${BRESET}$FGREEN $1 " + print "${BOLD}$(dt)${BGREEN}${FWHITE}${ISUCCESS}${BRESET}$FGREEN $1 " } warn() { - print "${BOLD}${BYELLOW}${FBLACK}${IWARN}${BRESET}${FYELLOW} Warning:${RESET} $1 " + print "${BOLD}$(dt)${BYELLOW}${FBLACK}${IWARN}${BRESET}${FYELLOW} Warning:${RESET} $1 " } error() { - print "${BOLD}${BLRED}${FWHITE}${IERROR} Error: ${BRESET}${FLRED} $1 " >&2 + print "${BOLD}$(dt)${BLRED}${FWHITE}${IERROR} Error: ${BRESET}${FLRED} $1 " >&2 } fatal() { - print "${BOLD}${BRED}${FWHITE}${IFATAL} FATAL: $1 " >&2 + print "${BOLD}$(dt)${BRED}${FWHITE}${IFATAL} FATAL: $1 " >&2 print_stacktrace } die() { error "${1:-halted}" - exit ${2:-100} + exit ${2:-255} } print_stacktrace() { @@ -294,6 +294,18 @@ print_stacktrace() { done } +# var='test var_dump' +# var_dump var +# debug 'test debug' +# verbose 'test verbose' +# info 'test info' +# note 'test note' +# success 'test success' +# warn 'test warn' +# error 'test error' +# fatal 'test fatal' +# die 'test die' + ######################################################## # Tests ######################################################## @@ -609,4 +621,4 @@ git.require_clean_worktree() { # https://gitlab.com/kyb/autorsync/-/blob/master/ # https://lug.fh-swf.de/vim/vim-bash/StyleGuideShell.en.pdf # https://www.thegeekstuff.com/2010/06/bash-array-tutorial/ -# https://www.distributednetworks.com/linux-network-admin/module4/ephemeral-reserved-portNumbers.php +# https://www.distributednetworks.com/linux-network-admin/module4/ephemeral-reserved-portNumbers.php \ No newline at end of file