aboutsummaryrefslogtreecommitdiff
path: root/pb
diff options
context:
space:
mode:
authorPhilip Wittamore <philip@wittamore.com>2025-05-16 17:16:19 +0200
committerPhilip Wittamore <philip@wittamore.com>2025-05-16 17:16:19 +0200
commitd4bfe144de8330ecbf737d04e59d6069597a5ebc (patch)
tree7344dae86eb13181a517c8ecd38939517b77f5e3 /pb
parent71842f833dac41f652a0bf00cba97e3738aa3ad7 (diff)
downloadbashlib-d4bfe144de8330ecbf737d04e59d6069597a5ebc.tar.gz
bashlib-d4bfe144de8330ecbf737d04e59d6069597a5ebc.tar.bz2
bashlib-d4bfe144de8330ecbf737d04e59d6069597a5ebc.zip
update
Diffstat (limited to 'pb')
-rwxr-xr-xpb48
1 files changed, 48 insertions, 0 deletions
diff --git a/pb b/pb
new file mode 100755
index 0000000..d3eba2a
--- /dev/null
+++ b/pb
@@ -0,0 +1,48 @@
+#!/usr/bin/env bash
+
+# 256 colour functions usage
+# source ./pb
+# printf %b "$(bg 196)$(fg 254) RED $(nc)\n"
+
+nc () {
+ printf '\033[0;0m';
+ exit;
+}
+
+fg () {
+
+ if [ -z "$1" ] || [ "$1" -eq "$1" ] >/dev/null 2>&1; then
+ true
+ else
+ echo "bad parameter";
+ exit;
+ fi
+
+ local x
+ x=$(tput colors)
+
+ if (("$1" < 256)) && (("$x" > 255)); then
+ printf %s "\033[38;5;$1m"
+ fi
+
+}
+
+bg () {
+
+ if [ -z "$1" ] || [ "$1" -eq "$1" ] >/dev/null 2>&1; then
+ true
+ else
+ echo "bad parameter";
+ exit;
+ fi
+
+ local x
+ x=$(tput colors)
+
+ if (("$1" < 256)) && (("$x" > 255)); then
+ printf %s "\033[48;5;$1m"
+ fi
+
+}
+
+# end 256 colour functions