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