Skip to content

Lightweight cross-platform CLI tool for working with environment variables.

License

Notifications You must be signed in to change notification settings

ankddev/envfetch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

envfetch

Lightweight cross-platform CLI tool for working with environment variables
Build status Test status GitHub commit activity crates.io downloads crates.io version AUR version

Features

  • Print all environment variables
  • Get value of variable by name
    • Show similar variables if given variable not found
  • Set variable (temporary and permanent)
  • Delete variable (temporary and permanent)
  • Load variables from dotenv-style file (temporary and permanent)
  • Add string to the end of variable
  • Set and delete multiple variables at once

Get started

Installing

Packaging status

AUR (Arch Linux)

envfetch is available as a package in the AUR. You can install it with an AUR helper (e.g. paru):

$ paru -S envfetch

Scoop (Windows)

You can install envfetch from Scoop using this command:

scoop install https://gist.githubusercontent.com/ankddev/f6314b552aa021f676fc999ec697f833/raw/envfetch.json

Note, that it uses manifest, published only as GitHub Gist.

From DEB package (Linux, Debian-based)

You can download .deb package from releases and thhen execute:

sudo dpkg -i <deb-package>

Cargo (from crates.io)

You can install envfetch from Cargo (needs Rust installed):

$ cargo install envfetch

Cargo (from source)

Also, you can install it from source (needs Rust installed):

$ cargo install --git https://github.com/ankddev/envfetch envfetch

Download binary

Or, get binary from GitHub Actions (needs GutHub account) or releases

Using

To run envfetch, run envfetch <COMMAND> <ARGS> in your terminal. You can run envfetch help to see help message or envfetch --version to see program's version.

Command list

Set

Set environment variable and optionally run process.

Usage: envfetch set <KEY> <VALUE> [PROCESS], where:

  • KEY - name of environment variable
  • VALUE - value of environment variable
  • PROCESS - name of process which you want to run (optional if --global is used)

Options:

  • --help/-h - show help message
  • --global/-g - set variable permanently in system environment
    • On Windows: stores in registry
    • On Unix: stores in shell config (.bashrc, .zshrc, or config.fish)

For example:

$ envfetch set MY_VAR "Hello" "npm run"  # temporary for process
$ envfetch set MY_VAR "Hello" --global   # permanent system-wide

Add

Add value to the end of environment variable and optionally run the process

Usage: envfetch add <KEY> <VALUE> [PROCESS], where:

  • KEY - name of environment variable
  • VALUE - value of environment variable to add
  • PROCESS - name of process which you want to run (optional if --global is used)

Options:

  • --help/-h - show help message
  • --global/-g - update variable permanently in system environment
    • On Windows: stores in registry
    • On Unix: stores in shell config (.bashrc, .zshrc, or config.fish)

For example:

$ envfetch add PATH "../hello.exe" "crago run"  # temporary for process
$ envfetch add MY_VAR "Hello" --global   # permanent system-wide

Print

Print all environment variables

Usage: envfetch print

Options:

  • --help/-h - show help message

For example:

$ envfetch print
SHELL = "powershell"
windir = "C:\\Windows"
SystemDrive = "C:"
SystemRoot = "C:\\Windows"
...

It will print all environment variables in format VAR = "VALUE".

Get

Get value of environment variable

Usage: envfetch get <KEY>, where:

  • KEY - name of environment variable

Options:

  • --help/-h - show help message
  • --no-similar-names/-s - disable showing similar variables if variable not

For example:

$ envfetch get MY_VAR
"Hello"

It will print value of specified variable.

Delete

Delete variable and optionally start process.

Usage: envfetch delete <KEY> [PROCESS], where:

  • KEY - name of environment variable
  • PROCESS - name of command to run (optional if --global is used)

Options:

  • --help/-h - show help message
  • --global/-g - delete variable permanently from system environment

For example:

$ envfetch delete MY_VAR "npm run"  # temporary for process
$ envfetch delete MY_VAR --global   # permanent system-wide

Load

Load environment variables from dotenv-style file and optionally run process.

Usage: envfetch load [PROCESS], where:

  • PROCESS - name of process which you want to run (optional if --global is used)

Options:

  • --help/-h - show help message
  • --file <FILE>/-f <FILE> - relative or absolute path to file to read variables from. Note that it must be in .env format. By default, program loads variables from .env file in current directory.
  • --global/-g - load variables permanently into system environment

For example:

$ envfetch load "npm run"                    # temporary for process
$ envfetch load --global                     # permanent system-wide
$ envfetch load --global --file .env.prod    # permanent from specific file

Note

When using --global flag:

  • On Windows, variables are stored in the registry under HKEY_CURRENT_USER\Environment
  • On Unix-like systems, variables are stored in shell configuration files (.bashrc, .zshrc, or config.fish)

Without --global flag, variables are only set for the current process run

Building from source

  • Install Rust. If it already installed, update with
$ rustup update
  • Fork this project using button Fork on the top of this page
  • Clone your fork (replace <YOUR_USERNAME> with your username on GitHub):
$ git clone https://github.com/<YOUR_USERNAME>/envfetch.git
  • Go to directory, where you cloned envfetch:
$ cd envfetch
  • Run program using Cargo (replace <COMMAND> and <ARGS> to your command and args):
$ cargo run -- <COMMAND> <ARGS>

See Also

Contributing

$ cargo fmt
$ cargo clippy --fix
  • Run tests with
$ cargo test
  • Push changes
  • Open pull request