@@ -88,17 +88,22 @@ function iniget_multiline {
8888}
8989
9090# Determinate is the given option present in the INI file
91- # ini_has_option config-file section option
91+ # ini_has_option [-sudo] config-file section option
9292function ini_has_option {
9393 local xtrace
9494 xtrace=$( set +o | grep xtrace)
9595 set +o xtrace
96+ local sudo=" "
97+ if [ $1 == " -sudo" ]; then
98+ sudo=" sudo "
99+ shift
100+ fi
96101 local file=$1
97102 local section=$2
98103 local option=$3
99104 local line
100105
101- line=$( sed -ne " /^\[$section \]/,/^\[.*\]/ { /^$option [ \t]*=/ p; }" " $file " )
106+ line=$( $sudo sed -ne " /^\[$section \]/,/^\[.*\]/ { /^$option [ \t]*=/ p; }" " $file " )
102107 $xtrace
103108 [ -n " $line " ]
104109}
@@ -173,8 +178,10 @@ function iniset {
173178 xtrace=$( set +o | grep xtrace)
174179 set +o xtrace
175180 local sudo=" "
181+ local sudo_option=" "
176182 if [ $1 == " -sudo" ]; then
177183 sudo=" sudo "
184+ sudo_option=" -sudo "
178185 shift
179186 fi
180187 local file=$1
@@ -187,11 +194,11 @@ function iniset {
187194 return
188195 fi
189196
190- if ! grep -q " ^\[$section \]" " $file " 2> /dev/null; then
197+ if ! $sudo grep -q " ^\[$section \]" " $file " 2> /dev/null; then
191198 # Add section at the end
192199 echo -e " \n[$section ]" | $sudo tee --append " $file " > /dev/null
193200 fi
194- if ! ini_has_option " $file " " $section " " $option " ; then
201+ if ! ini_has_option $sudo_option " $file " " $section " " $option " ; then
195202 # Add it
196203 $sudo sed -i -e " /^\[$section \]/ a\\
197204$option = $value
@@ -228,7 +235,7 @@ function iniset_multiline {
228235 # the reverse order. Do a reverse here to keep the original order.
229236 values=" $v ${values} "
230237 done
231- if ! grep -q " ^\[$section \]" " $file " ; then
238+ if ! $sudo grep -q " ^\[$section \]" " $file " ; then
232239 # Add section at the end
233240 echo -e " \n[$section ]" | $sudo tee --append " $file " > /dev/null
234241 else
0 commit comments