fixes to work as a generic included function script
This commit is contained in:
parent
25974c025d
commit
3734837047
71
bashtools.sh
71
bashtools.sh
|
@ -1,17 +1,19 @@
|
||||||
#!/bin/bash
|
#!/usr/bin/env /bin/bash
|
||||||
|
true
|
||||||
$(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."
|
echo "ERROR: This script should be sourced ('. $0') rather than run directly."
|
||||||
|
return 2>/dev/null # jist in case
|
||||||
exit 1;
|
exit 1;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $1 != "reload" && -n $HAVE_BASHTOOLS ]]; then
|
if [[ $1 != "reload" && -n $HAVE_BASHTOOLS ]]; then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
HAVE_BASHTOOLS=1
|
export HAVE_BASHTOOLS=1
|
||||||
|
|
||||||
BASHTOOLS_DIR="${HOME}/.bashtools"
|
export BASHTOOLS_DIR="${HOME}/.bashtools"
|
||||||
|
|
||||||
SPINNERFRAMES='|/-\'
|
SPINNERFRAMES='|/-\'
|
||||||
SPINNERFILE="$BASHTOOLS_DIR/spinner.pid"
|
SPINNERFILE="$BASHTOOLS_DIR/spinner.pid"
|
||||||
|
@ -19,35 +21,36 @@ 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}"
|
||||||
|
|
||||||
BOLD="\033[1m"
|
export BOLD="\033[1m"
|
||||||
PLAIN="\033[0m"
|
export PLAIN="\033[0m"
|
||||||
ITALIC="\033[3m"
|
export ITALIC="\033[3m"
|
||||||
STRIKE="\033[9m"
|
export STRIKE="\033[9m"
|
||||||
UNDERLINE="\033[4m"
|
export UNDERLINE="\033[4m"
|
||||||
RED="\033[31m"
|
export RED="\033[31m"
|
||||||
YELLOW="\033[33m"
|
export YELLOW="\033[33m"
|
||||||
GREEN="\033[32m"
|
export GREEN="\033[32m"
|
||||||
BLUE="\033[34m"
|
export BLUE="\033[34m"
|
||||||
MAGENTA="\033[35m"
|
export MAGENTA="\033[35m"
|
||||||
CYAN="\033[36m"
|
export CYAN="\033[36m"
|
||||||
ORANGE="${PLAIN}\033[38;2;255;165;0m"
|
export ORANGE="${PLAIN}\033[38;2;255;165;0m"
|
||||||
ORANGEBOLD="${BOLD}\033[38;2;255;220;0m"
|
export ORANGEBOLD="${BOLD}\033[38;2;255;220;0m"
|
||||||
|
|
||||||
MAGENTARGB="${PLAIN}\033[38;2;208;65;126m"
|
export MAGENTARGB="${PLAIN}\033[38;2;208;65;126m"
|
||||||
MAGENTARGBBOLD="${BOLD}\033[38;2;255;135;196m"
|
export MAGENTARGBBOLD="${BOLD}\033[38;2;255;135;196m"
|
||||||
|
|
||||||
INFORMCOL="$ORANGE"
|
export INFOCOL="$CYAN"
|
||||||
INFORMCOLB="$ORANGEBOLD"
|
export INFORMCOL="$ORANGE"
|
||||||
NOTIFYCOL="$MAGENTARGB"
|
export INFORMCOLB="$ORANGEBOLD"
|
||||||
NOTIFYCOLB="$MAGENTARGBBOLD"
|
export NOTIFYCOL="$MAGENTARGB"
|
||||||
|
export NOTIFYCOLB="$MAGENTARGBBOLD"
|
||||||
|
|
||||||
GREY="\033[38;2;110;110;110m"
|
export GREY="\033[38;2;110;110;110m"
|
||||||
LINK="$BLUE$UNDERLINE"
|
export LINK="$BLUE$UNDERLINE"
|
||||||
|
|
||||||
UNDERLINE_PRINTED=$(echo -en "$UNDERLINE")
|
export UNDERLINE_PRINTED=$(echo -en "$UNDERLINE")
|
||||||
UNDERLINE_LENGTH=${#UNDERLINE_PRINTED}
|
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() {
|
function noansi() {
|
||||||
local allcols c
|
local allcols c
|
||||||
|
@ -58,7 +61,7 @@ function noansi() {
|
||||||
}
|
}
|
||||||
|
|
||||||
# provide specific "bold" colour
|
# 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
|
local col bcol str minusn="" autobold=0
|
||||||
|
|
||||||
while [[ ${1:0:1} == "-" ]]; do
|
while [[ ${1:0:1} == "-" ]]; do
|
||||||
|
@ -89,8 +92,8 @@ function ccecho() { # [-n] [-s] col boldcol "str"
|
||||||
}
|
}
|
||||||
|
|
||||||
# use bold version of supplied colour
|
# use bold version of supplied colour
|
||||||
function cecho() { # [-n] col "str"
|
function csecho() { # [-n] col "str"
|
||||||
ccecho -s $*
|
cecho -s $*
|
||||||
}
|
}
|
||||||
|
|
||||||
alias try=notify
|
alias try=notify
|
||||||
|
@ -108,6 +111,11 @@ function inform() {
|
||||||
cecho "$INFORMCOL" "$INFORMCOLB" "^b* ^p$* "
|
cecho "$INFORMCOL" "$INFORMCOLB" "^b* ^p$* "
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function info() {
|
||||||
|
[[ $AUTOYES -eq 1 ]] && return
|
||||||
|
csecho "${INFOCOL}" "^b>>^p $*"
|
||||||
|
}
|
||||||
|
|
||||||
function ok() {
|
function ok() {
|
||||||
local msg=${*:-ok}
|
local msg=${*:-ok}
|
||||||
stop_spinner
|
stop_spinner
|
||||||
|
@ -568,3 +576,6 @@ function dnslookup() { # $1 = a_record_to_look_up
|
||||||
return $rv
|
return $rv
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#declare -fx $(bash -c "source $0 &> /dev/null; compgen -A function")
|
||||||
|
declare -fx $(compgen -A function | grep -v ^_)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue