1- # ---
2- # Config functions [@bashly-upgrade config]
3- # This file is a part of Bashly standard library
4- #
5- # Usage:
6- # - In your script, set the CONFIG_FILE variable. For rxample:
7- # CONFIG_FILE=settings.ini.
8- # If it is unset, it will default to 'config.ini'.
9- # - Use any of the functions below to access the config file.
10- # ---
11-
12- # Create a new config file.
13- # There is normally no need to use this function, it is used by other
14- # functions as needed.
1+ # # Config functions [@bashly-upgrade config]
2+ # # This file is a part of Bashly standard library
3+ # #
4+ # # Usage:
5+ # # - In your script, set the CONFIG_FILE variable. For rxample:
6+ # # CONFIG_FILE=settings.ini.
7+ # # If it is unset, it will default to 'config.ini'.
8+ # # - Use any of the functions below to access the config file.
9+ # #
10+ # # Create a new config file.
11+ # # There is normally no need to use this function, it is used by other
12+ # # functions as needed.
13+ # #
1514config_init () {
1615 CONFIG_FILE=${CONFIG_FILE:= config.ini}
1716 [[ -f " $CONFIG_FILE " ]] || touch " $CONFIG_FILE "
1817}
1918
20- # Get a value from the config.
21- # Usage: result=$(config_get hello)
19+ # # Get a value from the config.
20+ # # Usage: result=$(config_get hello)
2221config_get () {
2322 local key=$1
2423 local regex=" ^$key *= *(.+)$"
@@ -36,8 +35,8 @@ config_get() {
3635 echo " $value "
3736}
3837
39- # Add or update a key=value pair in the config.
40- # Usage: config_set key value
38+ # # Add or update a key=value pair in the config.
39+ # # Usage: config_set key value
4140config_set () {
4241 local key=$1
4342 shift
@@ -68,8 +67,8 @@ config_set() {
6867 printf " %b\n" " $output " > " $CONFIG_FILE "
6968}
7069
71- # Delete a key from the config.
72- # Usage: config_del key
70+ # # Delete a key from the config.
71+ # # Usage: config_del key
7372config_del () {
7473 local key=$1
7574
@@ -87,19 +86,19 @@ config_del() {
8786 printf " %b\n" " $output " > " $CONFIG_FILE "
8887}
8988
90- # Show the config file
89+ # # Show the config file
9190config_show () {
9291 config_init
9392 cat " $CONFIG_FILE "
9493}
9594
96- # Return an array of the keys in the config file.
97- # Usage:
98- #
99- # for k in $(config_keys); do
100- # echo "- $k = $(config_get "$k")";
101- # done
102- #
95+ # # Return an array of the keys in the config file.
96+ # # Usage:
97+ # #
98+ # # for k in $(config_keys); do
99+ # # echo "- $k = $(config_get "$k")";
100+ # # done
101+ # #
103102config_keys () {
104103 local regex=" ^([a-zA-Z0-9_\-\/\.]+) *="
105104
@@ -117,13 +116,13 @@ config_keys() {
117116 echo " ${keys[@]} "
118117}
119118
120- # Returns true if the specified key exists in the config file.
121- # Usage:
122- #
123- # if config_has_key "key" ; then
124- # echo "key exists"
125- # fi
126- #
119+ # # Returns true if the specified key exists in the config file.
120+ # # Usage:
121+ # #
122+ # # if config_has_key "key" ; then
123+ # # echo "key exists"
124+ # # fi
125+ # #
127126config_has_key () {
128127 [[ $( config_get " $1 " ) ]]
129128}
0 commit comments