fix csecho to not strip multuple spaces
This commit is contained in:
parent
fdcd0eabdc
commit
d0991b572b
67
bashtools.sh
67
bashtools.sh
|
@ -1,26 +1,42 @@
|
||||||
#!/usr/bin/env /bin/bash
|
#!/usr/bin/env /bin/bash
|
||||||
true # need a successful command before the sourced script check
|
|
||||||
|
export BASHTOOLS_DIR="${HOME}/.bashtools"
|
||||||
|
if [[ $1 == "install" ]]; then
|
||||||
|
mkdir -p "$BASHTOOLS_DIR"
|
||||||
|
cp -a $0 "$BASHTOOLS_DIR/"
|
||||||
|
echo "Bashtools has been installed in $BASHTOOLS_DIR"
|
||||||
$(return 2>/dev/null)
|
$(return 2>/dev/null)
|
||||||
rv="$?"
|
rv="$?"
|
||||||
if [[ $rv -ne 0 ]]; then
|
if [[ $rv -ne 0 ]]; then
|
||||||
echo "ERROR: This script should be sourced ('. $0') rather than run directly."
|
exit 1
|
||||||
return 2>/dev/null # jist in case
|
else
|
||||||
exit 1;
|
return
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
#true # need a successful command before the sourced script check
|
||||||
|
#$(return 2>/dev/null)
|
||||||
|
#rv="$?"
|
||||||
|
#if [[ $rv -ne 0 ]]; then
|
||||||
|
# echo "ERROR: This script should be sourced ('. $0') rather than run directly."
|
||||||
|
# return 2>/dev/null # jist in case
|
||||||
|
# exit 1;
|
||||||
|
#fi
|
||||||
|
|
||||||
|
|
||||||
if [[ $1 != "reload" && -n $HAVE_BASHTOOLS ]]; then
|
if [[ $1 != "reload" && -n $HAVE_BASHTOOLS ]]; then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
export HAVE_BASHTOOLS=1
|
export HAVE_BASHTOOLS=1
|
||||||
|
|
||||||
export BASHTOOLS_DIR="${HOME}/.bashtools"
|
SPINDELAY=0.05 # delay in ms between spinner frames
|
||||||
|
|
||||||
SPINNERFRAMES='|/-\'
|
SPINNERFRAMES='|/-\'
|
||||||
SPINNERFILE="$BASHTOOLS_DIR/spinner.pid"
|
SPINNERFILE="$BASHTOOLS_DIR/spinner.pid"
|
||||||
|
|
||||||
[[ ! -e $BASHTOOLS_DIR ]] && mkdir "$BASHTOOLS_DIR"
|
[[ ! -e $BASHTOOLS_DIR ]] && mkdir "$BASHTOOLS_DIR"
|
||||||
[[ -e $SPINNERFILE ]] && rm -f "${SPINNERFILE}"
|
[[ -e $SPINNERFILE ]] && rm -f "${SPINNERFILE}"
|
||||||
|
|
||||||
|
|
||||||
export BOLD="\033[1m"
|
export BOLD="\033[1m"
|
||||||
export PLAIN="\033[0m"
|
export PLAIN="\033[0m"
|
||||||
export ITALIC="\033[3m"
|
export ITALIC="\033[3m"
|
||||||
|
@ -93,27 +109,34 @@ function cecho() { # [-n] [-s] col boldcol "str"
|
||||||
|
|
||||||
# use bold version of supplied colour
|
# use bold version of supplied colour
|
||||||
function csecho() { # [-n] col "str"
|
function csecho() { # [-n] col "str"
|
||||||
cecho -s $*
|
local args col
|
||||||
|
while [[ $# -gt 2 ]]; do
|
||||||
|
args="$args $1"
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
col="$1"
|
||||||
|
shift
|
||||||
|
cecho $args -s "$col" "$*"
|
||||||
}
|
}
|
||||||
|
|
||||||
alias try=notify
|
alias try=notify
|
||||||
function notify() {
|
function notify() {
|
||||||
#echo -en "${NOTIFYCOLB}* ${NOTIFYCOL}$*...${PLAIN} "
|
#echo -en "${NOTIFYCOLB}* ${NOTIFYCOL}$*...${PLAIN} "
|
||||||
cecho -n "$NOTIFYCOL" "$NOTIFYCOLB" "^b* ^p$*... "
|
cecho -n "$NOTIFYCOL" "$NOTIFYCOLB" "^b* ^p$*... " >/dev/stderr
|
||||||
if [[ $NOSPINNER -ne 1 ]]; then
|
if [[ $NOSPINNER -ne 1 ]]; then
|
||||||
start_spinner &
|
start_spinner &
|
||||||
tput civis
|
tput civis >/dev/stderr
|
||||||
fi
|
fi
|
||||||
innotify=1
|
innotify=1
|
||||||
}
|
}
|
||||||
|
|
||||||
function inform() {
|
function inform() {
|
||||||
cecho "$INFORMCOL" "$INFORMCOLB" "^b* ^p$* "
|
cecho "$INFORMCOL" "$INFORMCOLB" "^b* ^p$* " >/dev/stderr
|
||||||
}
|
}
|
||||||
|
|
||||||
function info() {
|
function info() {
|
||||||
[[ $AUTOYES -eq 1 ]] && return
|
[[ $AUTOYES -eq 1 ]] && return
|
||||||
csecho "${INFOCOL}" "^b>>^p $*"
|
csecho "${INFOCOL}" "^b>>^p $*" >/dev/stderr
|
||||||
}
|
}
|
||||||
|
|
||||||
function ok() {
|
function ok() {
|
||||||
|
@ -121,7 +144,7 @@ function ok() {
|
||||||
stop_spinner
|
stop_spinner
|
||||||
[[ $innotify -eq 0 ]] && return 1
|
[[ $innotify -eq 0 ]] && return 1
|
||||||
innotify=0
|
innotify=0
|
||||||
echo -e "$GREEN$msg$PLAIN"
|
echo -e "$GREEN$msg$PLAIN" >/dev/stderr
|
||||||
}
|
}
|
||||||
|
|
||||||
function fail() {
|
function fail() {
|
||||||
|
@ -129,23 +152,23 @@ function fail() {
|
||||||
stop_spinner
|
stop_spinner
|
||||||
[[ $innotify -eq 0 ]] && return 1
|
[[ $innotify -eq 0 ]] && return 1
|
||||||
innotify=0
|
innotify=0
|
||||||
echo -e "$RED$msg$PLAIN"
|
echo -e "$RED$msg$PLAIN" >/dev/stderr
|
||||||
}
|
}
|
||||||
|
|
||||||
function partial() {
|
function partial() {
|
||||||
local msg=${*:-failed}
|
local msg=${*:-partial}
|
||||||
stop_spinner
|
stop_spinner
|
||||||
[[ $innotify -eq 0 ]] && return 1
|
[[ $innotify -eq 0 ]] && return 1
|
||||||
innotify=0
|
innotify=0
|
||||||
echo -e "$YELLOW$msg$PLAIN"
|
echo -e "$YELLOW$msg$PLAIN" >/dev/stderr
|
||||||
}
|
}
|
||||||
|
|
||||||
function warn() {
|
function warn() {
|
||||||
cecho -s "$YELLOW" "^bWarning: ^p$*"
|
cecho -s "$YELLOW" "^bWarning: ^p$*" >/dev/stderr
|
||||||
}
|
}
|
||||||
|
|
||||||
function error() {
|
function error() {
|
||||||
cecho -s "$RED" "^bERROR: ^p$*"
|
cecho -s "$RED" "^bERROR: ^p$*" >/dev/stderr
|
||||||
}
|
}
|
||||||
|
|
||||||
function start_spinner() {
|
function start_spinner() {
|
||||||
|
@ -153,14 +176,14 @@ function start_spinner() {
|
||||||
|
|
||||||
(
|
(
|
||||||
len=${#SPINNERFRAMES}
|
len=${#SPINNERFRAMES}
|
||||||
echo -n " "
|
echo -n " " >/dev/stderr
|
||||||
while [ 1 ] ; do
|
while [ 1 ] ; do
|
||||||
echo -en "\b${SPINNERFRAMES:$idx:1}"
|
echo -en "\b${SPINNERFRAMES:$idx:1}" >/dev/stderr
|
||||||
idx=$((idx + 1))
|
idx=$((idx + 1))
|
||||||
[[ $idx -ge $len ]] && idx=0
|
[[ $idx -ge $len ]] && idx=0
|
||||||
sleep 0.1
|
sleep $SPINDELAY
|
||||||
done
|
done
|
||||||
) 2>/dev/null &
|
) &
|
||||||
spid=$!
|
spid=$!
|
||||||
echo $spid >>"$SPINNERFILE"
|
echo $spid >>"$SPINNERFILE"
|
||||||
}
|
}
|
||||||
|
@ -179,7 +202,7 @@ function stop_spinner() {
|
||||||
fi
|
fi
|
||||||
done < "$SPINNERFILE"
|
done < "$SPINNERFILE"
|
||||||
rm -f "$SPINNERFILE"
|
rm -f "$SPINNERFILE"
|
||||||
tput cnorm
|
tput cnorm >/dev/stderr
|
||||||
}
|
}
|
||||||
|
|
||||||
function getsysstats() {
|
function getsysstats() {
|
||||||
|
|
Loading…
Reference in New Issue