Rework .bash template

The config file functionality was something I never used, and for good reason
Best get rid of it
This commit is contained in:
Salt 2022-06-06 23:54:22 -05:00
parent cbd575b7b1
commit 98c4e79442

View File

@ -10,11 +10,6 @@ set -e
# Read-only set-once variables # Read-only set-once variables
declare -r _name="$(basename -- "$0")" declare -r _name="$(basename -- "$0")"
# Options # Options
declare -a _config=(
[foo]="bar"
[baz]="bop"
)
declare _optconfigfile="${XDG_CONFIG_HOME:-$HOME/.config}/${_name}.conf"
declare -i _opthelp declare -i _opthelp
declare -i _optverbose declare -i _optverbose
# Working variables # Working variables
@ -66,21 +61,12 @@ has() {
done done
return 0 return 0
} }
validateline() {
# Takes a line and errors if it's just whitespace or a comment
local linenows=${1//[[:space:]]}
if ! [ "${1#\#}" = "$1" ] || [ -z "$linenows" ]; then
return 1
fi
return 0
}
# Core program functions # Core program functions
printhelp() { printhelp() {
cat << EOF cat << EOF
Usage: $_name [OPTION]... Usage: $_name [OPTION]...
-c [FILE] Load the given file in place of the usual config file
-h Print this help text -h Print this help text
-v Print more status messages. Stacks -v Print more status messages. Stacks
@ -94,11 +80,8 @@ main() {
# Parse out arguments # Parse out arguments
while [ -n "$1" ]; do while [ -n "$1" ]; do
# Parse out flags # Parse out flags
while getopts ":c:hv" opt; do while getopts ":hv" opt; do
case $opt in case $opt in
c)
_optconfigfile="$OPTARG"
;;
h) h)
_opthelp=1 _opthelp=1
;; ;;
@ -123,21 +106,6 @@ main() {
done done
# Early hook for help # Early hook for help
[ -n "$_opthelp" ] && printhelp && exit 0 [ -n "$_opthelp" ] && printhelp && exit 0
# Parse out a config file if it exists
if [ -f "$_optconfigfile" ]; then
log "Loading config file" 2
while read line; do
# If the line has an equals sign and isn't a comment
if [ "$line" != "${line#*=}" ] && validateline "$line"; then
local key="${line%=*}"
local value="${line#*=}"
_config[$key]="$value"
log "Setting $key to $value" 2
fi
done < "$_optconfigfile"
else
warn "Could not find configuration file" 2
fi
# Validate critical options # Validate critical options
# TODO: That # TODO: That
# Validate core program dependencies # Validate core program dependencies
@ -147,7 +115,7 @@ main() {
fi fi
# Do the do # Do the do
# TODO: The do # TODO: The do%HERE%
warn "Nothing to do" warn "Nothing to do"
exit 0 exit 0
} }