summary refs log tree commit diff
diff options
context:
space:
mode:
authorSingustromo <singustromo@disroot.org>2023-11-05 00:41:53 +0100
committerSingustromo <singustromo@disroot.org>2023-11-05 00:41:53 +0100
commit6aa6562805eec575c057e46a5ed79110a61538c4 (patch)
tree342427ccccd4c4ef2b6a99f0ec4e23cd996a2551
parent3eb73e6d65c344cd99df2d89173b57e22be270a4 (diff)
downloadbash-framework-6aa6562805eec575c057e46a5ed79110a61538c4.tar.gz
bash-framework-6aa6562805eec575c057e46a5ed79110a61538c4.zip
Many small improvements
-rwxr-xr-xlib/bootstrap.sh64
-rw-r--r--vision4
-rwxr-xr-xyour-script.sh6
3 files changed, 37 insertions, 37 deletions
diff --git a/lib/bootstrap.sh b/lib/bootstrap.sh
index 993bfd0..72373a6 100755
--- a/lib/bootstrap.sh
+++ b/lib/bootstrap.sh
@@ -4,9 +4,9 @@
 ### BOOTSTRAP FUNCTIONS ###
 ###########################
 
-Array::contains() { [[ " ${@:2} " =~ " $1 " ]]; }
+Array:contains() { [[ " ${@:2} " =~ " $1 " ]]; }
 
-File::absolute_path() {
+File:absolute_path() {
 	local file="${1:?no filepath}"
 	if [ "${file::1}" == "/" ]; then
 		[ -r "$file" ] || return
@@ -22,7 +22,7 @@ File::absolute_path() {
 }
 
 # Kills the script with previous exit code and optional error message
-System::die() {
+System:die() {
 	local return_value="$?"
 	
 	if [ $# -gt 0 ]; then
@@ -32,46 +32,46 @@ System::die() {
 	exit "$return_value"
 }
 
-System::SourceFile() {
+System:SourceFile() {
 	local libPath="${1:?no file provided}"; shift
 
-	libPath="$(File::absolute_path "$libPath")" \
+	libPath="$(File:absolute_path "$libPath")" \
 		|| return
 	
 	## already imported? -> let's return
 	# if declare -f "$libPath" &> /dev/null &&
-	[ -n "${_VOID_IMPORTS[*]}" ] \
-	&& Array::contains "$libPath" "${_VOID_IMPORTS[@]}" \
-		&& [ "${_VOID_ALLOW_FILERELOAD}" == 'false' ] \
+	[ -n "${_PRISM_IMPORTS[*]}" ] \
+	&& Array:contains "$libPath" "${_PRISM_IMPORTS[@]}" \
+		&& [ "${_PRISM_ALLOW_FILERELOAD}" == 'false' ] \
 		&& return
 	
 	# Check syntax
 	/usr/bin/env bash -n "$libPath" \
 		&& builtin source "$libPath" "$@" \
-		&& _VOID_IMPORTS+=( "$libPath" )
+		&& _PRISM_IMPORTS+=( "$libPath" )
 }
 
-System::SourcePath() {
+System:SourcePath() {
 	local file libPath="${1:?no path specified}"
 	shift
 
 	if [ -d "$libPath" ]; then
 		for file in "$libPath"/*.sh; do 
-			System::SourceFile "$file" "$@" || return
+			System:SourceFile "$file" "$@" || return
 		done
 		return
 	fi
-	System::SourceFile "$libPath" "$@" \
-		|| System::SourceFile "${libPath}.sh" "$@"
+	System:SourceFile "$libPath" "$@" \
+		|| System:SourceFile "${libPath}.sh" "$@"
 }
 
-System::ImportOne() {
+System:ImportOne() {
 	local libPath="$1"
 	local requestedPath="$libPath"
 
 	shift
 	[ "${requestedPath::2}" == './' ] && requestedPath="${requestedPath:2}"
-	requestedPath="${_VOID_ROOT}/${requestedPath}"
+	requestedPath="${_PRISM_ROOT}/${requestedPath}"
 
 	# try relative to parent script
 	# try with parent
@@ -81,28 +81,28 @@ System::ImportOne() {
 	{
 		local localPath="$( cd "${BASH_SOURCE[1]%/*}" && pwd )"
 		localPath="${localPath}/${libPath}"
-		System::SourcePath "${localPath}" "$@"
+		System:SourcePath "${localPath}" "$@"
 	} && return
 
-	System::SourcePath "${requestedPath}" "$@" \
-		|| System::SourcePath "${libPath}" "$@" \
-		|| System::SourcePath "${_VOID_LIBPATH}/${libPath}" "$@" \
-		|| System::SourcePath "${_VOID_ROOT}/${libPath}" "$@"
+	System:SourcePath "${requestedPath}" "$@" \
+		|| System:SourcePath "${libPath}" "$@" \
+		|| System:SourcePath "${_PRISM_LIBPATH}/${libPath}" "$@" \
+		|| System:SourcePath "${_PRISM_ROOT}/${libPath}" "$@"
 }
 
-System::Import() {
+System:Import() {
 	local libPath
 	for libPath in "$@"; do
-		System::ImportOne "$libPath" || return
+		System:ImportOne "$libPath" || return
 	done
 }
 
 ## note: aliases are visible inside functions only if
 ## they were initialized AFTER they were created
 ## this is the reason why we have to load files in a specific order
-System::Bootstrap() {
-	System::Import array/contains \
-		|| System::die "Unable to bootstrap (missing lib directory?)\n"
+System:Bootstrap() {
+	System:Import array/contains \
+		|| System:die "Unable to bootstrap (missing lib directory?)\n"
 }
 
 ######################
@@ -115,16 +115,16 @@ export PS4='+(${BASH_SOURCE##*/}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
 # return the highest exitcode in a chain of pipes.
 set -o pipefail
 
-_VOID_LIBPATH="$(realpath "${BASH_SOURCE[0]}")"
-declare -g -r _VOID_LIBPATH="${_VOID_LIBPATH%/*}"
-declare -g -r _VOID_ROOT="${_VOID_LIBPATH%/*}"
+_PRISM_LIBPATH="$(realpath "${BASH_SOURCE[0]}")"
+declare -g -r _PRISM_LIBPATH="${_PRISM_LIBPATH%/*}"
+declare -g -r _PRISM_ROOT="${_PRISM_LIBPATH%/*}"
 
-declare -g -a _VOID_IMPORTS
+declare -g -a _PRISM_IMPORTS
 
-: "${_VOID_ALLOW_FILERELOAD:=false}"
+: "${_PRISM_ALLOW_FILERELOAD:=false}"
 
 import() {
-	eval "System::Import $*"
+	eval "System:Import $*"
 }
 
-System::Bootstrap && declare -g -r _VOID_BOOTSTRAPPED=true
+System:Bootstrap && declare -g -r _PRISM_BOOTSTRAPPED=true
diff --git a/vision b/vision
index 127900b..d13f416 100644
--- a/vision
+++ b/vision
@@ -1,7 +1,7 @@
-== VOID BASH FRAMEWORK ==
+== PRISM BASH FRAMEWORK ==
 * a bash standard library
 
-* similiar to infinity framework
+* similiar to shellscript-loader & infinity framework
   - much simpler, though
   - no object oriented code
   - removed alias declarations
diff --git a/your-script.sh b/your-script.sh
index dce2c09..4b9a9a0 100755
--- a/your-script.sh
+++ b/your-script.sh
@@ -1,7 +1,7 @@
 #!/usr/bin/env bash
 
 ## BOOTSTRAP ##
-workdir="$(realpath "${BASH_SOURCE[0]}")"
+workdir="$(realpath "${BASH_SOURCE[-1]}")"
 readonly workdir="${workdir%/*}"
 . "$workdir"/lib/bootstrap.sh
 
@@ -16,10 +16,10 @@ import util/log util/msg util/function/list util/print_spaces
 #
 #  import ../dir/...
 
+## YOUR CODE GOES HERE ##
+
 Util::log "imports:\n" "${_VOID_IMPORTS[@]}"
 
 Function::list
 
 Util::print_spaces 15
-
-## YOUR CODE GOES HERE ##