aboutsummaryrefslogtreecommitdiff
path: root/.config/shell/posix-functions/create_POSIX_dotenv.sh
blob: 9e5121db328f0f05c94430b343178ee2b886b65a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
create_POSIX_dotenv() {
    if [ -f .env ]; then
        echo "# auto-generated .env.sh file" > .env.sh
        while IFS= read -r line; do
            if [ "${line#\#}" != "$line" ] || [ -z "$line" ]; then
                continue
            fi
            key=$(echo "$line" | cut -d '=' -f 1)
            value=$(echo "$line" | cut -d '=' -f 2-)
            echo "export $key=\"$value\"" >> .env.sh
        done < .env
        echo ".env.sh file created successfully."
    else
        echo ".env file not found in current directory."
    fi
}