git.lirion.de

Of git, get, and gud

aboutsummaryrefslogtreecommitdiffstats
path: root/fs/usr/lib/lirion/ln-initfunctions
diff options
context:
space:
mode:
authormail_redacted_for_web 2024-06-16 13:07:26 +0200
committermail_redacted_for_web 2024-06-16 13:07:26 +0200
commit14354b96301e252f52b5315e63b43f44dbac5314 (patch)
tree0fd91d25caa6a681ca8eaab4f3d3f6031afc0b3e /fs/usr/lib/lirion/ln-initfunctions
downloadlirion-initfunctions-14354b96301e252f52b5315e63b43f44dbac5314.tar.bz2
InComm
Diffstat (limited to 'fs/usr/lib/lirion/ln-initfunctions')
-rwxr-xr-xfs/usr/lib/lirion/ln-initfunctions104
1 files changed, 104 insertions, 0 deletions
diff --git a/fs/usr/lib/lirion/ln-initfunctions b/fs/usr/lib/lirion/ln-initfunctions
new file mode 100755
index 0000000..81d74e6
--- /dev/null
+++ b/fs/usr/lib/lirion/ln-initfunctions
@@ -0,0 +1,104 @@
+#!/usr/bin/env bash
+# shellcheck disable=SC2119,SC2120
+
+# This serves as an alternative to "init functions". So the objective is to display
+# an abstract about what a script is doing in the background and delivering a status.
+# E.g.:
+# - lnbegin "Doing awesome stuff"
+# - do-something -q 2>/dev/null
+# - case "$?" in
+# 0) lnok ;;
+# 255) lnwarn "Something uncritical went wrong" ;;
+# *) lnfail "kaboom!" 101;;
+# esac
+#
+# This script uses unicode characters. A "legacy" variant where we fall back
+# to having e.g. "[ OK ]" instead of a checkmark is planned. (Earlier versions had that, too.)
+#
+# For a demo of the looks, use SCRIPTNAME -d.
+#
+# LICENCE: LGPLv3
+# AUTHOR: coding æt lirion dot de
+
+declare -x LNINITMSG
+
+function lnbegin {
+ printf "[⏲] %b\\033[s..." "$1"
+ export LNINITMSG="$1"
+}
+function lnok {
+ printf "\\r\\033[92m[✔] %b\\033[u\\033[K" "$LNINITMSG"
+ [ -n "$1" ]&&printf " \\033[37m(%b)\\033[0m" "$1"
+ printf "\\033[92m.\033[0m\\n"
+ unset LNINITMSG
+}
+function lnsucc {
+ lnok "$1"
+}
+function lninfo {
+ printf "\\r[ℹ]\\033[u\\033[K"
+ [ -n "$1" ]&&printf ": %b" "$1"
+ printf ".\\n"
+ unset LNINITMSG
+}
+function lnwarn {
+ printf "\\r\\033[33m[\\033[1m⚠\\033[0m\\033[33m] %b\\033[u\\033[K" "$LNINITMSG"
+ [ -n "$1" ]&&printf " \\033[37m(%b)\\033[0m" "$1"
+ printf "\\033[33m.\\033[0m\\n"
+ unset LNINITMSG
+ return 255
+}
+function lnfail {
+ printf "\\r\\033[31m[✖] \\033[31m%b\\033[u\\033[K" "$LNINITMSG" # was 91m before
+ [ -n "$1" ]&&printf " \\033[37m(%b)\\033[0m" "$1"
+ printf "\\033[31m.\\033[0m\\n"
+ unset LNINITMSG
+ [ -n "$2" ]&&return "$2"||return 1
+}
+function lnskip {
+ printf "\\r\\033[37m[↪] %b\\033[u\\033[K" "$LNINITMSG"
+ [ -n "$1" ]&&printf " \\033[37m(%b)\\033[0m" "$1"
+ printf "\\033[37m.\033[0m\\n"
+ unset LNINITMSG
+}
+function lnretry {
+ printf "\\r\\033[36m[↻] %b\\033[u\\033[K" "$LNINITMSG"
+ [ -n "$1" ]&&printf " \\033[37m(%b)\\033[0m" "$1"
+ printf "\\033[36m.\\033[0m\\n"
+ unset LNINITMSG
+}
+function lnquit {
+ printf "\\r\\033[34m[⏻] %b\\033[u\\033[K" "$LNINITMSG"
+ [ -n "$1" ]&&printf " \\033[37m(%b)\\033[0m" "$1"
+ printf "\\033[34m.\\033[0m\\n"
+ unset LNINITMSG
+}
+function lnprog {
+ # here, we neither have a newline at the end of the function nor do we
+ # remove the LNINITMSG variable. It is designated for additional
+ # information _during execution_.
+ [ -z "$1" ] && return 0
+ printf "\\033[u\\033[K \\033[38;5;237m(%b)\\033[0m" "$1"
+}
+function lnsmil {
+ printf "\\r\\033[35m[☺] %b\\033[u\\033[K" "$LNINITMSG"
+ [ -n "$1" ]&&printf " \\033[37m(%b)\\033[0m" "$1"
+ printf "\\033[35m.\\033[0m\\n"
+ unset LNINITMSG
+}
+function demo {
+ lnbegin "Progress message";sleep 0.31337;lnprog "additional progress message (does not terminate)";printf -- " -- \\n"
+ lnbegin "OK message";sleep 0.31337;lnok "additional success message"
+ lnbegin "Info message";sleep 0.31337;lninfo "information without further steps / return value"
+ lnbegin "Warning message";sleep 0.31337;lnwarn "additional warning info"
+ lnbegin "Failure message";sleep 0.31337;lnfail "additional failure info"
+ lnbegin "Skip message";sleep 0.31337;lnskip "additional skip reason"
+ lnbegin "Retry message";sleep 0.31337;lnretry "additional reason for new run"
+ lnbegin "Quit message";sleep 0.31337;lnquit "additional quit information"
+ lnbegin "Lulz";sleep 0.31337;lnsmil
+ unset LNINITMSG
+}
+if [ "$1" == "-d" ] || [ "$1" == "--demo" ];then
+ demo
+ exit 0
+fi