From 49468383f23ba4ed8e19e4e16e4d1dbb793a3235 Mon Sep 17 00:00:00 2001 From: Nathaniel Landau Date: Fri, 22 Oct 2021 15:56:22 -0400 Subject: [PATCH] add _clearLine_ --- .vscode/shellscript.code-snippets | 2 +- utilities/alerts.bash | 19 +++++++++++++++++++ utilities/macOS.bash | 20 +++++++++++++------- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/.vscode/shellscript.code-snippets b/.vscode/shellscript.code-snippets index 9d5218f..46a28ce 100644 --- a/.vscode/shellscript.code-snippets +++ b/.vscode/shellscript.code-snippets @@ -60,7 +60,7 @@ "\t\t#\t\t\t\t\t\t\t 1: Failure", "\t\t#\t\t\t\t\tstdout: ", "\t\t# USAGE:", - "\t\t#\t\t\t\t\t${1:name} \"@\"", + "\t\t#\t\t\t\t\t_${1:name}_ \"@\"", "\t\t", "\t\t [[ $# == 0 ]] && fatal \"Missing required argument to ${FUNCNAME[0]}\"", "\t\t", diff --git a/utilities/alerts.bash b/utilities/alerts.bash index bbc94b2..4a822f4 100644 --- a/utilities/alerts.bash +++ b/utilities/alerts.bash @@ -300,3 +300,22 @@ _columnizeOutput_() { printf "%-${_leftIndent}s%-${_leftColumn}b %b\n" "" "${_key}" "${_line}" done <<<"$(fold -w${_rightWrapLength} -s <<<"${_value}")" } + +_clearLine_() { + # DESC: + # Clears output in the terminal on the specified line number. + # ARGS: + # $1 (Optional): Line number to clear. (Defaults to 1) + # OUTS: + # 0: Success + # 1: Failure + # USAGE: + # _clearLine_ "2" + + [ ! "$(declare -f "_isTerminal_")" ] && fatal "${FUNCNAME[0]} needs function _isTerminal_" + + if _isTerminal_; then + local _line=${1:-1} + printf "\033[%sA\033[2K" "${_line}" + fi +} diff --git a/utilities/macOS.bash b/utilities/macOS.bash index dea8126..8e6fe4b 100644 --- a/utilities/macOS.bash +++ b/utilities/macOS.bash @@ -62,14 +62,20 @@ _useGNUutils_() { # GNU utilities can be added to MacOS using Homebrew [ ! "$(declare -f "_setPATH_")" ] && fatal "${FUNCNAME[0]} needs function _setPATH_" + [ ! "$(declare -f "_detectOS_")" ] && fatal "${FUNCNAME[0]} needs function _detectOS_" - if _setPATH_ \ - "/usr/local/opt/gnu-tar/libexec/gnubin" \ - "/usr/local/opt/coreutils/libexec/gnubin" \ - "/usr/local/opt/gnu-sed/libexec/gnubin" \ - "/usr/local/opt/grep/libexec/gnubin"; then - return 0 + if [[ $(_detectOS_) == mac ]]; then + if _setPATH_ \ + "/usr/local/opt/gnu-tar/libexec/gnubin" \ + "/usr/local/opt/coreutils/libexec/gnubin" \ + "/usr/local/opt/gnu-sed/libexec/gnubin" \ + "/usr/local/opt/grep/libexec/gnubin"; then + return 0 + else + return 1 + fi else - return 1 + # Always return 0 on non-MacOS + return 0 fi }