OSDN Git Service

added echo_color
authorkokkiemouse <kokkiemouse@localhost.localdomain>
Thu, 10 Sep 2020 13:35:58 +0000 (22:35 +0900)
committerkokkiemouse <kokkiemouse@localhost.localdomain>
Thu, 10 Sep 2020 13:35:58 +0000 (22:35 +0900)
Signed-off-by: kokkiemouse <kokkiemouse@localhost.localdomain>
echo_color [new file with mode: 0755]

diff --git a/echo_color b/echo_color
new file mode 100755 (executable)
index 0000000..79ff33b
--- /dev/null
@@ -0,0 +1,34 @@
+#!/usr/bin/env bash
+# SPDX-License-Identifier: GPL-3.0
+#
+# mk-linux419
+# Twitter: @fascoder_4
+# Email  : m.k419sabuaka@gmail.com
+#
+# (c) 2019-2020 Fascode Network.
+#
+# echo_color
+#
+
+while getopts 't:b:d:' arg; do
+    case ${arg} in
+        t) textcolor="${OPTARG}" ;;
+        b) backcolor="${OPTARG}" ;;
+        d) deco="${OPTARG}" ;;
+        *) echo "Invalid argument '${OPTARG}'" ;;
+    esac
+done
+
+shift $((OPTIND - 1))
+
+if [[ -n "${deco}" ]]; then
+    case ${deco} in
+        0) decotypes="sgr 0" ;;
+        1) decotypes="bold" ;;
+        4) decotypes="smul" ;;
+        5) decotypes="blink" ;;
+        *) echo "Invalid argument '${deco}'" ;;
+    esac
+fi
+
+echo "$([[ -n "${textcolor}" ]] && tput setaf "${textcolor}")$([[ -n "${backcolor}" ]] && tput setab "${backcolor}")$([[ -n "${decotypes}" ]] && tput "${decotypes}")${*}$(tput sgr0)"
\ No newline at end of file