summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xMakefile4
-rw-r--r--src/xilib.sh23
2 files changed, 26 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 3892e3f..d5a2718 100755
--- a/Makefile
+++ b/Makefile
@@ -7,7 +7,7 @@ DIST=dist
.DEFAULT_GOAL := build
-install: install-hbar install-colors install-parseconf install-shtests install-glyphs install-xitui
+install: install-hbar install-colors install-parseconf install-shtests install-glyphs install-xitui install-xilib
check: check-parseconf
build: make-dist hbar shtests parseconf colors
@@ -36,6 +36,8 @@ install-glyphs: src/glyphs.sh
install-xitui: src/xitui.sh
install -Dm755 src/xitui.sh ${DESTDIR}${PREFIX}/lib
+install-xilib: src/xilib.sh
+ install -Dm755 src/xilib.sh ${DESTDIR}${PREFIX}/lib
check-parseconf: shtests parseconf test/parseconf.sh
${DIST}/shtests ./test/parseconf.sh
diff --git a/src/xilib.sh b/src/xilib.sh
new file mode 100644
index 0000000..56e2592
--- /dev/null
+++ b/src/xilib.sh
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+# format a number into a bytes, kibibytes, mebibytes, or gibibytes
+#
+format_bytes () {
+ case "1" in
+ "$(($1>=1<<30))") printf "$(($1>>30))GiB";;
+ "$(($1>=1<<20))") printf "$(($1>>20))MiB";;
+ "$(($1>=1<<10))") printf "$(($1>>10))kiB";;
+ *) printf "$1B";;
+ esac
+}
+
+# ensure that the user is a root user
+#
+checkroot () {
+ [ "$(id -u)" = "0" ] || {
+ printf "${RED}Please run as root!\n"
+ exit 1
+ }
+}
+
+