Skip to content

Commit

Permalink
Use export instead of -g declare option.
Browse files Browse the repository at this point in the history
When converting the configuration from the old single value approach
to the new array one, the `typeset` and `declare` builtins are
used. The problem is that the variables must be used as global
variables, so that once the configuration is reloaded, the variable
value is used.
However, seems that `declare - g` is not a valid builtin on Bash on
Mac OSX.
Therefore, when the variable is written to the configuration file, an
explicit `export` for the variable is written too. This ensures that
the variable becomes globally scoped.

Also fix a problem of not-evaluated variable.

Related to #52
Close #54
  • Loading branch information
fluca1978 committed Jun 20, 2022
1 parent 7bfe3fb commit 76645e8
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions bin/pgenv
Original file line number Diff line number Diff line change
Expand Up @@ -618,12 +618,14 @@ pgenv_configuration_write_variable(){
echo "# $comment" >> "$file"
fi

# if no value supplied, put a comment

if [[ "$name" =~ _OPTIONS$ ]]; then
# declare has no way to output a global variable
# that is then needed when reloading configuration !
declare -p "${name}" | sed 's/declare/declare -g /' >> "$file"
declare -p "${name}" >> "$file"
echo "export ${name}" >> "$file"
else
# if no value supplied, put a comment
if [ -z "$value" ]; then
echo -n "#" >> "$file"
fi
Expand Down Expand Up @@ -1209,7 +1211,7 @@ case $1 in
fi

# warn if no configuration was loaded
if [ ! -z "PGENV_WARNINGS" ]; then
if [ ! -z "$PGENV_WARNINGS" ]; then
if [ -z "$PGENV_CONFIGURATION_FILE" ]; then
seconds=5
cat <<EOF
Expand Down

0 comments on commit 76645e8

Please sign in to comment.