Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bep/firstupdotenv
Loads env from the first firstup.env it finds.
https://github.com/bep/firstupdotenv
environment-variables golang zsh
Last synced: 3 months ago
JSON representation
Loads env from the first firstup.env it finds.
- Host: GitHub
- URL: https://github.com/bep/firstupdotenv
- Owner: bep
- Created: 2022-09-02T07:24:39.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-08-09T09:48:11.000Z (6 months ago)
- Last Synced: 2024-10-11T05:43:55.967Z (4 months ago)
- Topics: environment-variables, golang, zsh
- Language: Go
- Homepage:
- Size: 9.77 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
This is a simple Go program that finds the first `firstup.env` file starting from the current directory walking upward, stopping before the root folder (meaning: any `/firstup.env` file will not be read).
It will write the env vars as export statements. It will also store the list of keys set in a separate environment variable and unset those next time `firstupdotenv` is run.
The output may then look like this:
```bash
unset FOO
unset BAR
export FIRSTUPDOTENV_CURRENT_SET_ENV=FOO,BAR
export FOO=value1
export BAR=value2
```The `.env` format is a file on the form `key=value`. It ignores empty lines and lines starting with # and lines without an equals sign. If the same key is defined more than once, the last will win.
To install:
```bash
go install github.com/bep/firstupdotenv@latest
```This tool is meant to be used in combination with some shell extension that triggers when you `cd` into a directory. If you use the [Z shell](https://en.wikipedia.org/wiki/Z_shell), putting this in your `.zshrc` will work:
```
autoload -U add-zsh-hookfirstupdotenv_after_cd() {
source <(firstupdotenv)
}add-zsh-hook chpwd firstupdotenv_after_cd
```