You've already forked bash-ini-parser
mirror of
https://github.com/albfan/bash-ini-parser.git
synced 2025-08-07 18:02:52 +03:00
@@ -10,6 +10,12 @@ function debug {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function cfg_parser {
|
function cfg_parser {
|
||||||
|
shopt -p extglob &> /dev/null
|
||||||
|
CHANGE_EXTGLOB=$?
|
||||||
|
if [ $CHANGE_EXTGLOB = 1 ]
|
||||||
|
then
|
||||||
|
shopt -s extglob
|
||||||
|
fi
|
||||||
ini="$(<$1)" # read the file
|
ini="$(<$1)" # read the file
|
||||||
ini="${ini//[/\\[}" # escape [
|
ini="${ini//[/\\[}" # escape [
|
||||||
debug
|
debug
|
||||||
@@ -19,15 +25,9 @@ function cfg_parser {
|
|||||||
debug
|
debug
|
||||||
ini=( ${ini[*]//;*/} ) # remove comments with ;
|
ini=( ${ini[*]//;*/} ) # remove comments with ;
|
||||||
debug
|
debug
|
||||||
ini=( ${ini[*]/ =/=} ) # remove tabs before =
|
ini=( ${ini[*]/#+([[:space:]])/} ) # remove init whitespace
|
||||||
debug
|
debug "whitespace around"
|
||||||
ini=( ${ini[*]/# /} ) # remove init tabs #TODO: remove all not just one
|
ini=( ${ini[*]/*([[:space:]])=*([[:space:]])/=} ) # remove whitespace around =
|
||||||
debug
|
|
||||||
ini=( ${ini[*]/# /} ) # remove init space #TODO: remove all not just one
|
|
||||||
debug
|
|
||||||
ini=( ${ini[*]/= /=} ) # remove tabs after =
|
|
||||||
debug
|
|
||||||
ini=( ${ini[*]/ = /=} ) # remove anything with a space around =
|
|
||||||
debug
|
debug
|
||||||
ini=( ${ini[*]/#\\[/\}$'\n'cfg.section.} ) # set section prefix
|
ini=( ${ini[*]/#\\[/\}$'\n'cfg.section.} ) # set section prefix
|
||||||
debug
|
debug
|
||||||
@@ -48,6 +48,11 @@ function cfg_parser {
|
|||||||
ini[${#ini[*]} + 1]='}' # add the last brace
|
ini[${#ini[*]} + 1]='}' # add the last brace
|
||||||
debug
|
debug
|
||||||
eval "$(echo "${ini[*]}")" # eval the result
|
eval "$(echo "${ini[*]}")" # eval the result
|
||||||
|
if [ $CHANGE_EXTGLOB = 1 ]
|
||||||
|
then
|
||||||
|
shopt -u extglob
|
||||||
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function cfg_writer {
|
function cfg_writer {
|
||||||
|
Reference in New Issue
Block a user