Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fabberr/setenv
Export environment variables from file.
https://github.com/fabberr/setenv
bash-script environment-variables shell-script
Last synced: 10 days ago
JSON representation
Export environment variables from file.
- Host: GitHub
- URL: https://github.com/fabberr/setenv
- Owner: fabberr
- License: gpl-3.0
- Created: 2024-10-27T02:57:55.000Z (12 days ago)
- Default Branch: master
- Last Pushed: 2024-10-27T07:23:28.000Z (11 days ago)
- Last Synced: 2024-10-28T06:42:00.885Z (10 days ago)
- Topics: bash-script, environment-variables, shell-script
- Language: Shell
- Homepage:
- Size: 26.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# setenv
Export environment variables from file.
## Description
Utility shell script for loading environment variables defined in `.env` files, with support for automatic expansion of relative paths into absolute paths.
## Dependencies
Currently the script is only available for command line interpreters compatible with [`bash`](https://www.gnu.org/software/bash/) syntax.
Tested with `bash` on Linux, but should work out of the box on any UNIX-like operating system on a variety of shells.
## Usage
This script was **not** designed to be invoked directly, instead use the [`source`](https://www.gnu.org/software/bash/manual/html_node/Bash-Builtins.html#index-source) builtin command to ensure the variables are [exported](https://www.gnu.org/software/bash/manual/html_node/Bourne-Shell-Builtins.html#index-export) into the current shell session instead of just the script's subshell.
Because of this design, the script file doesn't need execute permissions, and uses `return` statements instead of `exit` for implementing control flow.To load the variables, simply invoke the script through the `source` command in the same directory the `.env` file is located. If no `` is given, it defaults to a `dev.env` file located in the current directory. The file must exist.
```sh
# Load variables from `dev.env`
source setenv.sh [options]# Load variables from
source setenv.sh [options]
```For the full documentation, see the script source file.
## Installing
The recommended way to install the script is to clone the repo locally, copy the scrip to a separate directory, then create an [alias](https://www.gnu.org/software/bash/manual/html_node/Aliases.html) for the script with the `source` command already added.
```sh
# 1. Clone the repository
SETENV_REPO="./scripts/setenv"
git clone [email protected]:fabberr/setenv.git $SETENV_REPO# 2. Install
SETENV_ROOT="./dev-tools"
mkdir -p $SETENV_ROOT && cd $SETENV_ROOT
cp "$SETENV_REPO/src/setenv.sh" .# 3. Register alias
echo "alias 'setenv'='source $(realpath setenv.sh)'" >> ~/.bash_aliases
source ~/.bash_aliases
```## Updating
To update the script, pull any changes from `origin/master` into your local repo and repeat only step 2 of the installation process.
```sh
# Pull changes from origin
git switch master
git pull origin master
```