Last active
October 26, 2024 07:06
-
-
Save donnaken15/2e1345bdb44cae19fa395f188fc3bef3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/printf %.0s%.0s%.0s%.0s%.0s%.0sThis is a utility which cannot be used standalone.\nUsage: source dotload [appname]\n | |
# dash compatible barebones conf loader | |
# | |
# making this separate for the sake of not copy pasting this across | |
# utilities i will make that allow configuration (usually not (lol)) | |
[ -z "$1" ] && { | |
echo 'dotload: No configuration name provided.' | |
return 1 | |
} | |
local conf="$1" | |
local ns="${dotload_namespace:-dk15}" # just because | |
[ "$(dirname "$conf")" = '.' ] && conf="$HOME/.config/$ns/$1" | |
export confpfx=__ay2zx1_ | |
[ -f "$conf" ] && | |
sed -n -e 's/^\s*\([a-z_][a-z_0-9]*\)\s*=\s*\(.*\)$/\1#\2/mip' "$conf" | | |
while IFS=# read -r k v; do; export "${confpfx}${k}"="$v"; done | |
# load values to variables in the main script | |
function userval() { | |
local varname="${confpfx}${1}" | |
export "${1}"="${(P)varname:-${2}}" | |
unset "${varname}" | |
} | |
# delete comments: -e '/^\(#.*\)\?$/d' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment