#env-var #variables #env #environment

env_perm

Sets environment variables in your profile

4 releases

0.1.3 Jun 20, 2019
0.1.2 Jun 20, 2019
0.1.1 Jan 1, 2019
0.1.0 Dec 21, 2018

#8 in #variable

Download history 71/week @ 2024-08-04 66/week @ 2024-08-11 58/week @ 2024-08-18 67/week @ 2024-08-25 66/week @ 2024-09-01 69/week @ 2024-09-08 64/week @ 2024-09-15 106/week @ 2024-09-22 66/week @ 2024-09-29 14/week @ 2024-10-06 49/week @ 2024-10-13 50/week @ 2024-10-20 71/week @ 2024-10-27 90/week @ 2024-11-03 9/week @ 2024-11-10 29/week @ 2024-11-17

200 downloads per month
Used in moltenvk_deps

MIT license

6KB
62 lines

env_perm

This crate allows you to permanently set environment variables

Examples

// Check if DUMMY is set, if not set it to 1
// export DUMMY=1
env_perm::check_or_set("DUMMY", 1).expect("Failed to find or set DUMMY");
// Append $HOME/some/cool/bin to $PATH
// export PATH= "$HOME/some/cool/bin:$PATH"
env_perm::append("PATH", "$HOME/some/cool/bin").expect("Couldn't find PATH");
// Sets a variable without checking if it exists.
// Note you need to use a raw string literal to include ""
// export DUMMY="/something"
env_perm::set("DUMMY", r#""/something""#).expect("Failed to set DUMMY");

Usage

This crate simply appends to your .bash_profile or .bash_login or .profile in that order. It will create a .bash_profile file if none of the above are found in your home directory. ie. /Users/me/.bash_profile.

I have only tested this on macOS but it should work on any unix system. I want to add windows support soon.

Contributions are welcome.


lib.rs:

This crate allows you to permanently set environment variables

Examples

// Check if DUMMY is set, if not set it to 1
// export DUMMY=1
env_perm::check_or_set("DUMMY", 1).expect("Failed to find or set DUMMY");
// Append $HOME/some/cool/bin to $PATH
// export PATH= "$HOME/some/cool/bin:$PATH"
env_perm::append("PATH", "$HOME/some/cool/bin").expect("Couldn't find PATH");
// Sets a variable without checking if it exists.
// Note you need to use a raw string literal to include ""
// export DUMMY="/something"
env_perm::set("DUMMY", r#""/something""#).expect("Failed to set DUMMY");

Dependencies

~39–430KB