fixes to work as a generic included function script

This commit is contained in:
Rob Pearce 2022-03-13 11:25:49 +11:00
parent 25974c025d
commit 3734837047
1 changed files with 41 additions and 30 deletions

View File

@ -1,17 +1,19 @@
#!/bin/bash
#!/usr/bin/env /bin/bash
true
$(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
return
fi
HAVE_BASHTOOLS=1
export HAVE_BASHTOOLS=1
BASHTOOLS_DIR="${HOME}/.bashtools"
export BASHTOOLS_DIR="${HOME}/.bashtools"
SPINNERFRAMES='|/-\'
SPINNERFILE="$BASHTOOLS_DIR/spinner.pid"
@ -19,35 +21,36 @@ SPINNERFILE="$BASHTOOLS_DIR/spinner.pid"
[[ ! -e $BASHTOOLS_DIR ]] && mkdir "$BASHTOOLS_DIR"
[[ -e $SPINNERFILE ]] && rm -f "${SPINNERFILE}"
BOLD="\033[1m"
PLAIN="\033[0m"
ITALIC="\033[3m"
STRIKE="\033[9m"
UNDERLINE="\033[4m"
RED="\033[31m"
YELLOW="\033[33m"
GREEN="\033[32m"
BLUE="\033[34m"
MAGENTA="\033[35m"
CYAN="\033[36m"
ORANGE="${PLAIN}\033[38;2;255;165;0m"
ORANGEBOLD="${BOLD}\033[38;2;255;220;0m"
export BOLD="\033[1m"
export PLAIN="\033[0m"
export ITALIC="\033[3m"
export STRIKE="\033[9m"
export UNDERLINE="\033[4m"
export RED="\033[31m"
export YELLOW="\033[33m"
export GREEN="\033[32m"
export BLUE="\033[34m"
export MAGENTA="\033[35m"
export CYAN="\033[36m"
export ORANGE="${PLAIN}\033[38;2;255;165;0m"
export ORANGEBOLD="${BOLD}\033[38;2;255;220;0m"
MAGENTARGB="${PLAIN}\033[38;2;208;65;126m"
MAGENTARGBBOLD="${BOLD}\033[38;2;255;135;196m"
export MAGENTARGB="${PLAIN}\033[38;2;208;65;126m"
export MAGENTARGBBOLD="${BOLD}\033[38;2;255;135;196m"
INFORMCOL="$ORANGE"
INFORMCOLB="$ORANGEBOLD"
NOTIFYCOL="$MAGENTARGB"
NOTIFYCOLB="$MAGENTARGBBOLD"
export INFOCOL="$CYAN"
export INFORMCOL="$ORANGE"
export INFORMCOLB="$ORANGEBOLD"
export NOTIFYCOL="$MAGENTARGB"
export NOTIFYCOLB="$MAGENTARGBBOLD"
GREY="\033[38;2;110;110;110m"
LINK="$BLUE$UNDERLINE"
export GREY="\033[38;2;110;110;110m"
export LINK="$BLUE$UNDERLINE"
UNDERLINE_PRINTED=$(echo -en "$UNDERLINE")
UNDERLINE_LENGTH=${#UNDERLINE_PRINTED}
export UNDERLINE_PRINTED=$(echo -en "$UNDERLINE")
export UNDERLINE_LENGTH=${#UNDERLINE_PRINTED}
REGEXP_IP='^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$'
export REGEXP_IP='^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$'
function noansi() {
local allcols c
@ -58,7 +61,7 @@ function noansi() {
}
# provide specific "bold" colour
function ccecho() { # [-n] [-s] col boldcol "str"
function cecho() { # [-n] [-s] col boldcol "str"
local col bcol str minusn="" autobold=0
while [[ ${1:0:1} == "-" ]]; do
@ -89,8 +92,8 @@ function ccecho() { # [-n] [-s] col boldcol "str"
}
# use bold version of supplied colour
function cecho() { # [-n] col "str"
ccecho -s $*
function csecho() { # [-n] col "str"
cecho -s $*
}
alias try=notify
@ -108,6 +111,11 @@ function inform() {
cecho "$INFORMCOL" "$INFORMCOLB" "^b* ^p$* "
}
function info() {
[[ $AUTOYES -eq 1 ]] && return
csecho "${INFOCOL}" "^b>>^p $*"
}
function ok() {
local msg=${*:-ok}
stop_spinner
@ -568,3 +576,6 @@ function dnslookup() { # $1 = a_record_to_look_up
return $rv
}
#declare -fx $(bash -c "source $0 &> /dev/null; compgen -A function")
declare -fx $(compgen -A function | grep -v ^_)