aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Wittamore <philip@wittamore.com>2025-05-16 23:26:54 +0200
committerPhilip Wittamore <philip@wittamore.com>2025-05-16 23:26:54 +0200
commit2b91370ea1d0c954bd1309196f3549347fcedd90 (patch)
tree70d5ade226edbc9e62cc62a2946a0497a11d90b1
parentd8aace61bf50174c3ac9dda9b8dbc695994fd9e7 (diff)
downloadbashlib-2b91370ea1d0c954bd1309196f3549347fcedd90.tar.gz
bashlib-2b91370ea1d0c954bd1309196f3549347fcedd90.tar.bz2
bashlib-2b91370ea1d0c954bd1309196f3549347fcedd90.zip
update
-rwxr-xr-xcolour_test4
-rwxr-xr-xpb30
2 files changed, 28 insertions, 6 deletions
diff --git a/colour_test b/colour_test
index 57831f5..cbcd390 100755
--- a/colour_test
+++ b/colour_test
@@ -5,3 +5,7 @@
source ./pb
printf %b "$(pb_bg 196)$(pb_fg 254) RED $(pb_nc)\n"
+
+printf %b "$(pb_bg ABC)$(pb_fg 254) RED $(pb_nc)\n"
+
+printf %b "$(pb_bg )$(pb_fg 254) RED $(pb_nc)\n"
diff --git a/pb b/pb
index cc91933..3bbfe66 100755
--- a/pb
+++ b/pb
@@ -1,21 +1,39 @@
#!/usr/bin/env bash
+# is int
+pb_isint() {
+ if [[ $1 =~ ^[0-9]+$ ]] ; then
+ return 0
+ else
+ return 1
+ fi
+}
+
+# is number
+pb_isnum() {
+ if [[ $1 =~ ^[+-]?([0-9]+([.][0-9]*)?|\.[0-9]+)$ ]] ; then
+ return 0
+ else
+ return 1
+ fi
+}
+
# 256 colour functions
# usage:
# source ./pb
# printf %b "$(pb_bg 196)$(pb_fg 254) RED $(pb_nc)\n"
-pb_nc () {
+pb_nc() {
printf '\033[0;0m';
exit;
}
-pb_fg () {
+pb_fg() {
- if [ -z "$1" ] || ! [ "$1" -eq "$1" ] >/dev/null 2>&1; then
+ if [ -z "$1" ] || ! pb_isint "$1" ; then
return 1
fi
-
+
local x
x=$(tput colors)
@@ -27,9 +45,9 @@ pb_fg () {
}
-pb_bg () {
+pb_bg() {
- if [ -z "$1" ] || ! [ "$1" -eq "$1" ] >/dev/null 2>&1; then
+ if [ -z "$1" ] || ! pb_isint $1 ; then
return 1
fi