From 6c1ff8fe7947266e4c8e47a55f73542ce88b6fe9 Mon Sep 17 00:00:00 2001 From: Philip Wittamore Date: Sat, 17 May 2025 09:04:10 +0200 Subject: update --- pb | 53 ----------------------------------------------------- pb_colour | 47 +++++++++++++++++++++++++++++++++++++++++++++++ pb_number | 9 +++++++++ 3 files changed, 56 insertions(+), 53 deletions(-) delete mode 100755 pb create mode 100755 pb_colour create mode 100755 pb_number diff --git a/pb b/pb deleted file mode 100755 index 279bbe8..0000000 --- a/pb +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env bash - -#--- is number functions -# https://stackoverflow.com/questions/806906/how-do-i-test-if-a-variable-is-a-number-in-bash/806923#806923 -pb_isuint() { case $1 in '' | *[!0-9]* ) return 1;; esac ;} -pb_isint() { case ${1#[-+]} in '' | *[!0-9]* ) return 1;; esac ;} -pb_isunum() { case $1 in '' | . | *[!0-9.]* | *.*.* ) return 1;; esac ;} -pb_isnum() { case ${1#[-+]} in '' | . | *[!0-9.]* | *.*.* ) return 1;; esac ;} - -#--- 256 colour functions -# usage: -# source ./pb -# printf %b "$(pb_bg 196)$(pb_fg 254) RED $(pb_nc)\n" - -pb_nc() { - printf '\033[0;0m'; - exit; -} - -pb_fg() { - - if [ -z "$1" ] || ! pb_isuint "$1" ; then - return 1 - fi - - local x - x=$(tput colors) - - if (("$1" < 256)) && (("$x" > 255)); then - printf %s "\033[38;5;$1m" - fi - - return 0 - -} - -pb_bg() { - - if [ -z "$1" ] || ! pb_isuint "$1" ; then - return 1 - fi - - local x - x=$(tput colors) - - if (("$1" < 256)) && (("$x" > 255)); then - printf %s "\033[48;5;$1m" - fi - - return 0 -} - -# end 256 colour functions diff --git a/pb_colour b/pb_colour new file mode 100755 index 0000000..89f6354 --- /dev/null +++ b/pb_colour @@ -0,0 +1,47 @@ +#!/usr/bin/env bash + +#--- 256 colour functions +# requires pb_number +# usage: +# source ./pb +# printf %b "$(pb_bg 196)$(pb_fg 254) RED $(pb_nc)\n" + +pb_nc() { + printf '\033[0;0m'; + exit; +} + +pb_fg() { + + if [ -z "$1" ] || ! pb_isuint "$1" ; then + return 1 + fi + + local x + x=$(tput colors) + + if (("$1" < 256)) && (("$x" > 255)); then + printf %s "\033[38;5;$1m" + fi + + return 0 + +} + +pb_bg() { + + if [ -z "$1" ] || ! pb_isuint "$1" ; then + return 1 + fi + + local x + x=$(tput colors) + + if (("$1" < 256)) && (("$x" > 255)); then + printf %s "\033[48;5;$1m" + fi + + return 0 +} + +# end 256 colour functions diff --git a/pb_number b/pb_number new file mode 100755 index 0000000..40a96be --- /dev/null +++ b/pb_number @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +#--- is number functions +# https://stackoverflow.com/questions/806906/how-do-i-test-if-a-variable-is-a-number-in-bash/806923#806923 + +pb_isuint() { case $1 in '' | *[!0-9]* ) return 1;; esac ;} +pb_isint() { case ${1#[-+]} in '' | *[!0-9]* ) return 1;; esac ;} +pb_isunum() { case $1 in '' | . | *[!0-9.]* | *.*.* ) return 1;; esac ;} +pb_isnum() { case ${1#[-+]} in '' | . | *[!0-9.]* | *.*.* ) return 1;; esac ;} -- cgit v1.2.3