Skip to content

Instantly share code, notes, and snippets.

@AhmedAbouelkher
Last active April 4, 2024 23:33
Show Gist options
  • Save AhmedAbouelkher/e59cc74c59fd257848aab8d4dc272b51 to your computer and use it in GitHub Desktop.
Save AhmedAbouelkher/e59cc74c59fd257848aab8d4dc272b51 to your computer and use it in GitHub Desktop.
Create an `env.dart` files passed on the Environment Values passed and prefixed with `flutter_`
#!/bin/sh
# list all system env variables starting with flutter_ and put them in a array variable
values=$(env | grep ^flutter_)
# check if values is empty
if [ -z "$values" ]
then
echo "No environment variables found starting with flutter_"
exit 0
fi
strippedValues=()
# loop through all values and strip the flutter_ prefix
for value in $values
do
# strip the prefix
key=$(echo $value | sed 's/^flutter_//')
strippedValues+=($key)
done
envString=""
# loop through all values and print them
for envVariable in ${strippedValues[@]}
do
# split the key and value
key=$(echo $envVariable | cut -d '=' -f 1)
value=$(echo $envVariable | cut -d '=' -f 2)
# add the value to the envString
envString+="const $key = \"${value}\";\n"
done
# write the envString to the env.dart file
echo $envString > lib/env.dart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment