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:
parent
cbd575b7b1
commit
98c4e79442
@ -10,11 +10,6 @@ set -e
|
||||
# Read-only set-once variables
|
||||
declare -r _name="$(basename -- "$0")"
|
||||
# Options
|
||||
declare -a _config=(
|
||||
[foo]="bar"
|
||||
[baz]="bop"
|
||||
)
|
||||
declare _optconfigfile="${XDG_CONFIG_HOME:-$HOME/.config}/${_name}.conf"
|
||||
declare -i _opthelp
|
||||
declare -i _optverbose
|
||||
# Working variables
|
||||
@ -66,21 +61,12 @@ has() {
|
||||
done
|
||||
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
|
||||
printhelp() {
|
||||
cat << EOF
|
||||
Usage: $_name [OPTION]...
|
||||
|
||||
-c [FILE] Load the given file in place of the usual config file
|
||||
-h Print this help text
|
||||
-v Print more status messages. Stacks
|
||||
|
||||
@ -94,11 +80,8 @@ main() {
|
||||
# Parse out arguments
|
||||
while [ -n "$1" ]; do
|
||||
# Parse out flags
|
||||
while getopts ":c:hv" opt; do
|
||||
while getopts ":hv" opt; do
|
||||
case $opt in
|
||||
c)
|
||||
_optconfigfile="$OPTARG"
|
||||
;;
|
||||
h)
|
||||
_opthelp=1
|
||||
;;
|
||||
@ -123,21 +106,6 @@ main() {
|
||||
done
|
||||
# Early hook for help
|
||||
[ -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
|
||||
# TODO: That
|
||||
# Validate core program dependencies
|
||||
@ -147,7 +115,7 @@ main() {
|
||||
fi
|
||||
|
||||
# Do the do
|
||||
# TODO: The do
|
||||
# TODO: The do%HERE%
|
||||
warn "Nothing to do"
|
||||
exit 0
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user