summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordavidovski <david@davidovski.xyz>2026-10-01 10:34:33 +0100
committerdavidovski <david@davidovski.xyz>2026-10-01 10:34:33 +0100
commiteca55e60c29440c4e2e007b54ea1a1983e965954 (patch)
treea98173c09f69864cc25395bfdab67d682434854b /src
parentf20bd9d6369c2e1246dcdd4af26b085da99c18e0 (diff)
Add libhbar to shmkHEADmaster
Diffstat (limited to 'src')
-rw-r--r--src/lib/colors.h45
-rw-r--r--src/lib/colors.sh44
-rw-r--r--src/lib/libhbar.sh116
-rw-r--r--src/tools/colors.list (renamed from src/lib/colors.list)0
-rw-r--r--src/tools/generate_colors.sh (renamed from src/lib/generate_colors.sh)1
-rwxr-xr-xsrc/util/hbar.sh104
-rw-r--r--src/util/parseconf.sh42
-rw-r--r--src/util/shmk/shmk.README (renamed from src/util/shmk.README)12
-rwxr-xr-xsrc/util/shmk/shmk.sh (renamed from src/util/shmk.sh)52
9 files changed, 188 insertions, 228 deletions
diff --git a/src/lib/colors.h b/src/lib/colors.h
deleted file mode 100644
index e7bc26d..0000000
--- a/src/lib/colors.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * colors.h
- *
- * list of ansi color codes
- * provided by xiutils
- *
- */
-
-#define RESET ""
-#define BOLD ""
-#define BLACK ""
-#define RED ""
-#define GREEN ""
-#define YELLOW ""
-#define BLUE ""
-#define MAGENTA ""
-#define CYAN ""
-#define WHITE ""
-#define DEFAULT ""
-#define BG_BLACK ""
-#define BG_RED ""
-#define BG_GREEN ""
-#define BG_YELLOW ""
-#define BG_BLUE ""
-#define BG_MAGENTA ""
-#define BG_CYAN ""
-#define BG_WHITE ""
-#define BG_DEFAULT ""
-#define LIGHT_BLACK ""
-#define LIGHT_RED ""
-#define LIGHT_GREEN ""
-#define LIGHT_YELLOW ""
-#define LIGHT_BLUE ""
-#define LIGHT_MAGENTA ""
-#define LIGHT_CYAN ""
-#define LIGHT_WHITE ""
-#define LIGHT_DEFAULT ""
-#define BOLDBLACK ""
-#define BOLDRED ""
-#define BOLDGREEN ""
-#define BOLDYELLOW ""
-#define BOLDBLUE ""
-#define BOLDMAGENTA ""
-#define BOLDCYAN ""
-#define BOLDWHITE ""
diff --git a/src/lib/colors.sh b/src/lib/colors.sh
deleted file mode 100644
index 8e5de11..0000000
--- a/src/lib/colors.sh
+++ /dev/null
@@ -1,44 +0,0 @@
-#
-# colors.h
-#
-# list of ansi color codes
-# provided by xiutils
-#
-
-export RESET=$(printf "")
-export BOLD=$(printf "")
-export BLACK=$(printf "")
-export RED=$(printf "")
-export GREEN=$(printf "")
-export YELLOW=$(printf "")
-export BLUE=$(printf "")
-export MAGENTA=$(printf "")
-export CYAN=$(printf "")
-export WHITE=$(printf "")
-export DEFAULT=$(printf "")
-export BG_BLACK=$(printf "")
-export BG_RED=$(printf "")
-export BG_GREEN=$(printf "")
-export BG_YELLOW=$(printf "")
-export BG_BLUE=$(printf "")
-export BG_MAGENTA=$(printf "")
-export BG_CYAN=$(printf "")
-export BG_WHITE=$(printf "")
-export BG_DEFAULT=$(printf "")
-export LIGHT_BLACK=$(printf "")
-export LIGHT_RED=$(printf "")
-export LIGHT_GREEN=$(printf "")
-export LIGHT_YELLOW=$(printf "")
-export LIGHT_BLUE=$(printf "")
-export LIGHT_MAGENTA=$(printf "")
-export LIGHT_CYAN=$(printf "")
-export LIGHT_WHITE=$(printf "")
-export LIGHT_DEFAULT=$(printf "")
-export BOLDBLACK=$(printf "")
-export BOLDRED=$(printf "")
-export BOLDGREEN=$(printf "")
-export BOLDYELLOW=$(printf "")
-export BOLDBLUE=$(printf "")
-export BOLDMAGENTA=$(printf "")
-export BOLDCYAN=$(printf "")
-export BOLDWHITE=$(printf "")
diff --git a/src/lib/libhbar.sh b/src/lib/libhbar.sh
new file mode 100644
index 0000000..4489f09
--- /dev/null
+++ b/src/lib/libhbar.sh
@@ -0,0 +1,116 @@
+#!/bin/mksh -U
+#include colors
+#include xilib
+
+ADVANCE=" "
+
+move_up () {
+ [ ! "$1" = "0" ] &&
+ printf "\033[%dA" "$1" "0"
+}
+
+move_down () {
+ [ ! "$1" = "0" ] &&
+ printf "\033[%dB" "$1"
+}
+
+count_string () {
+ local c t
+ $human && {
+ c=$(format_bytes $completed)
+ t=$(format_bytes $total)
+ } || {
+ c=$1
+ t=$2
+ }
+ printf "[%s/%s]" $c $t
+}
+
+hbar () {
+ local width terminate human text color reset unit line count
+ width=$(tput cols)
+ color="$BLACK$BG_WHITE"
+ reset="$WHITE$BG_DEFAULT"
+ terminate=false
+ human=false
+ # dont write any real characters ya
+ notext=false
+ line=0
+
+ while getopts "T:c:r:u:l:hnt" opt; do
+ case "$opt" in
+ T)
+ text="$OPTARG"
+ ;;
+ c)
+ color="$OPTARG"
+ ;;
+ r)
+ reset="$OPTARG"
+ ;;
+ u)
+ unit="$OPTARG"
+ ;;
+ t)
+ terminate=true
+ ;;
+ h)
+ human=true
+ ;;
+ l)
+ line="$OPTARG"
+ ;;
+ n)
+ notext=true
+ esac
+ done
+
+ shift $((OPTIND-1))
+
+ [ "$#" -lt 2 ] && {
+ return 1
+ }
+
+ completed="$1"
+ total="$2"
+
+ move_up $line
+
+ count=$(count_string $completed $total)
+ #printf "\r$text"
+ printf "$RESET\r"
+ printf "$color"
+ reset_at=0
+
+ [ "$total" -gt "0" ] && reset_at=$(((completed*width)/total))
+
+ _x=0
+ while [ "$_x" -lt "$width" ]; do
+
+ if $notext; then
+ [ "$_x" -gt "$reset_at" ] && printf "$reset" || printf "$color"
+ printf "%s" "$ADVANCE"
+ else
+ [ "$_x" = "$reset_at" ] && printf "$reset"
+ if [ "${#text}" -gt 0 ]; then
+ printf "%s" "${text%%${text#?}}"
+ text="${text#?}"
+ else
+ if [ "$((width-${#count}))" = "$_x" ]; then
+ printf "%s" "${count%%${count#?}}"
+
+ count="${count#?}"
+ else
+ printf "$ADVANCE"
+ fi
+ fi
+ fi
+ _x=$((_x+1))
+ done
+
+ move_down $line
+
+ printf "$RESET"
+ $terminate && printf "\n"
+}
+
diff --git a/src/lib/colors.list b/src/tools/colors.list
index 0829a63..0829a63 100644
--- a/src/lib/colors.list
+++ b/src/tools/colors.list
diff --git a/src/lib/generate_colors.sh b/src/tools/generate_colors.sh
index 6e01d58..4d1e08f 100644
--- a/src/lib/generate_colors.sh
+++ b/src/tools/generate_colors.sh
@@ -1,5 +1,6 @@
#!/bin/bash
DIST=$1
+mkdir -p ${DIST}
headerfile=${DIST}/colors.h
shlib=${DIST}/colors.sh
diff --git a/src/util/hbar.sh b/src/util/hbar.sh
index 9518e66..230ff5d 100755
--- a/src/util/hbar.sh
+++ b/src/util/hbar.sh
@@ -1,108 +1,6 @@
#!/bin/mksh -U
-#include colors
-#include xilib
-move_up () {
- [ ! "$1" = "0" ] &&
- printf "\033[%dA" "$1" "0"
-}
-
-move_down () {
- [ ! "$1" = "0" ] &&
- printf "\033[%dB" "$1"
-}
-
-count_string () {
- local c t
- $human && {
- c=$(format_bytes $completed)
- t=$(format_bytes $total)
- } || {
- c=$1
- t=$2
- }
- printf "[%s/%s]" $c $t
-}
-
-hbar () {
- local width terminate human text color reset unit line count
- width=$(tput cols)
- color="$BLACK$BG_WHITE"
- reset="$WHITE$BG_DEFAULT"
- terminate=false
- human=false
- line=0
-
- while getopts "T:c:r:u:l:ht" opt; do
- case "$opt" in
- T)
- text="$OPTARG"
- ;;
- c)
- color="$OPTARG"
- ;;
- r)
- reset="$OPTARG"
- ;;
- u)
- unit="$OPTARG"
- ;;
- t)
- terminate=true
- ;;
- h)
- human=true
- ;;
- l)
- line="$OPTARG"
- ;;
- esac
- done
-
- shift $((OPTIND-1))
-
- [ "$#" -lt 2 ] && {
- return 1
- }
-
- completed="$1"
- total="$2"
-
- move_up $line
-
- count=$(count_string $completed $total)
- #printf "\r$text"
- printf "$RESET\r"
- printf "$color"
-
- reset_at=0
- [ "$total" -gt "0" ] && reset_at=$(((completed*width)/total))
-
- i=0
- while [ "$i" -lt "$width" ]; do
- [ "$i" = "$reset_at" ] && printf "$reset"
-
- [ "${#text}" -gt 0 ] && {
- printf "%s" "${text%%${text#?}}"
- text="${text#?}"
- } || {
- [ "$((width-${#count}))" = "$i" ] && {
- printf "%s" "${count%%${count#?}}"
- count="${count#?}"
- } || {
- printf " "
- }
- }
- i=$((i+1))
- done
-
- move_down $line
-
- printf "$RESET"
- $terminate && printf "\n"
-
- exit 0
-}
+#include libhbar
[ "$#" -eq "0" ] && {
printf "$RESET\n"
diff --git a/src/util/parseconf.sh b/src/util/parseconf.sh
index d215a99..17cb0ce 100644
--- a/src/util/parseconf.sh
+++ b/src/util/parseconf.sh
@@ -1,37 +1,37 @@
#!/bin/sh
usage () {
- printf "Usage $0 "
- echo << "EOF"
+printf "Usage $0 "
+echo << "EOF"
OPTIONS... [FILTER]
Print the parsed config file filtering by the keys
Arguments:
- -f file read configuration from a file, uses /dev/sdtin otherwise
- -v only print values
- -c n print the last [n]
+-f file read configuration from a file, uses /dev/sdtin otherwise
+-v only print values
+-c n print the last [n]
EOF
}
# parse a single config file line
#
parse_line() {
- [ "$#" = 0 ] && return
-
- local line="$@"
- local key=$1
-
- shift
- local value="$@"
- value=${value%#*}
-
- case $key in
- "include")
- cat $value | parse
- return
- ;;
- "]")
- IFS=.
+[ "$#" = 0 ] && return
+
+local line="$@"
+local key=$1
+
+shift
+local value="$@"
+value=${value%#*}
+
+case $key in
+ "include")
+ cat $value | parse
+ return
+ ;;
+ "]")
+ IFS=.
set -- $list
list="${*%${!#}}"
IFS=" "
diff --git a/src/util/shmk.README b/src/util/shmk/shmk.README
index a359fbc..43671ac 100644
--- a/src/util/shmk.README
+++ b/src/util/shmk/shmk.README
@@ -116,6 +116,14 @@ This feature is intended to be used with the `shtests` tool.
## Syntax and formatting
-shmk is intended to be as portable as possible, following exclusively POSIX shell syntax. This means that unlike in bash or csh, there is no formal structure for lists, instead whitespace separated strings are used. New lines or spaces both work, however for the sake of simplicity, newlines are prefered. The "standard" shmk syntax for a list is as follows
-`
+### shell features
+
+shmk is intended to be as portable as possible, following exclusively POSIX shell syntax. This means that unlike in bash or csh, there is no formal structure for lists, instead whitespace separated strings are used. New lines or spaces both work, however for the sake of simplicity, newlines are prefered.
+
+### env vars
+
+shmk exposes a few different environment variables in the build environment (ie to be used in custom build stages):
+
+- `${DIST}` - temporary "out" directory where libraries and binaries are placed.
+- `${PREFIX}` - where things will be installed
diff --git a/src/util/shmk.sh b/src/util/shmk/shmk.sh
index b4c040d..be5f00b 100755
--- a/src/util/shmk.sh
+++ b/src/util/shmk/shmk.sh
@@ -1,8 +1,9 @@
#!/bin/sh
-#
+#
# A tool to build a single executable from a collection of shell scripts
#include colors
+#include libhbar
PREFIX=${PREFIX:-/usr}
@@ -18,13 +19,15 @@ EOF
# _find_file filename
#
_find_file () {
- for p in $search_path; do
- for f in $p/$1.sh $p/$1; do
+ for p in $search_path; do
+ for f in $p/$1.sh $p/$1; do
$verbose \
&& printf "${LIGHT_BLACK}checking: $f\n" 1>&2
[ -f "$f" ] && {
- echo "$f"
+ $verbose \
+ && printf "${LIGHT_BLACK}found: $f for $1\n" 1>&2
+ echo "$f"
return 0
}
done
@@ -50,7 +53,10 @@ _parse_lines () {
# if we have already included this file, do not parse it
case "$included" in
- *"$file"*) ;;
+ *"$file"*)
+ $verbose \
+ && printf "${LIGHT_BLACK}already included $file, won't include twice\n" 1>&2
+ ;;
*)
cat $file | _parse_lines
included="$included $file"
@@ -103,15 +109,19 @@ interpret_shmk () {
. $1
local cmdlist=""
+ ## TODO override if already set
DIST="./dist"
- PROGS="$PROGS $(sed -rn "s/^prog_(.*)\s*\(\)\s*\{/\1/p" $1)"
- LIBS="$LIBS $(sed -rn "s/^lib_(.*)\s*\(\)\s*\{/\1/p" $1)"
- CHECKS="$CHECKS $(sed -rn "s/^check_(.*)\s*\(\)\s*\{/\1/p" $1)"
+ BUILDS="$(sed -rn "s/^build_(.*)\s*\(\)\s*\{/\1/p" $1) $BUILDS"
+ PROGS="$(sed -rn "s/^prog_(.*)\s*\(\)\s*\{/\1/p" $1) $PROGS "
+ LIBS="$(sed -rn "s/^lib_(.*)\s*\(\)\s*\{/\1/p" $1) $LIBS"
+ CHECKS="$(sed -rn "s/^check_(.*)\s*\(\)\s*\{/\1/p" $1) $CHECKS"
shift
- [ -z "$1" ] && set -- clean build check install
+ [ -z "$1" ] && set -- clean build check
while [ ! -z "$1" ]; do
case "$1" in
+ # install programs and libraries to system
+ #
install)
for prog in $PROGS; do
prog=$(basename $prog)
@@ -126,6 +136,9 @@ interpret_shmk () {
install -Dm755 $DIST/$lib ${DESTDIR}/${PREFIX}/lib/$lib.sh #Install library $lib"
done
;;
+
+ # install programs and libraries to system
+ #
uninstall)
for prog in $PROGS; do
prog=$(basename $prog)
@@ -140,16 +153,19 @@ interpret_shmk () {
rm $DIST/$lib ${DESTDIR}/${PREFIX}/lib/$lib.sh #Uninstall library $lib"
done
;;
+
clean)
[ -d "$DIST" ] && cmdlist="$cmdlist
rm -r $DIST #Clean"
;;
+
check)
for check in $CHECKS; do
command -v check_$check > /dev/null 2>&1 && cmdlist="$cmdlist
check_$check #Check $check"
done
;;
+
*) # build all programs
search_path="$DIST $search_path"
@@ -185,7 +201,15 @@ interpret_shmk () {
i=-1
echo "$cmdlist" | while read -r cmd; do
i=$((i+1))
- printf "${LIGHT_BLACK}[${LIGHT_BLUE}%s${LIGHT_BLACK}/${LIGHT_BLUE}%s${LIGHT_BLACK}] ${LIGHT_WHITE}%s${RESET}%s" "$i" "$len" "${cmd#*#}" "$($verbose && printf "\n" || printf "\r")"
+ outstring="$(printf "${LIGHT_BLACK}[${LIGHT_BLUE}%s${LIGHT_BLACK}/${LIGHT_BLUE}%s${LIGHT_BLACK}] ${LIGHT_WHITE}%s" \
+ "$i" "$len" "${cmd#*#}")"
+
+ printf "\r%s\r" "${outstring}" #"$($verbose && printf "\n\n" || printf "\n")"
+ if ! $verbose && command -v hbar > /dev/null 2>&1; then
+ printf "\n"
+ hbar -l 1 -r "${RESET}" -c "${BG_BLUE}" -n "$i" "$len"
+ fi
+
${cmd%#*} 2>&1 > $out || {
printf "\n${RED}Error $?\n"
exit 1
@@ -213,7 +237,7 @@ clean=false
}
while getopts ":e:I:o:chv" opt; do
- case "${opt}" in
+ case "${opt}" in
e)
entry_function="$OPTARG"
;;
@@ -224,8 +248,10 @@ while getopts ":e:I:o:chv" opt; do
clean=true
;;
I)
- search_path="$OPTARG
- $search_path"
+ search_path="
+ $OPTARG
+ $search_path
+ "
;;
v)
verbose=true