mirror of
https://github.com/natelandau/shell-scripting-templates.git
synced 2025-11-09 21:53:47 -05:00
add _clearLine_
This commit is contained in:
2
.vscode/shellscript.code-snippets
vendored
2
.vscode/shellscript.code-snippets
vendored
@@ -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",
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user