#env #environment #variable

set_env

Sets environment variables permanently across all major platforms

13 stable releases

1.3.4 Jun 12, 2022
1.3.1 May 29, 2022
1.0.2 Apr 20, 2022

#298 in Configuration

Download history 37/week @ 2023-10-31 19/week @ 2023-11-07 13/week @ 2023-11-14 29/week @ 2023-11-21 79/week @ 2023-11-28 71/week @ 2023-12-05 33/week @ 2023-12-12 20/week @ 2023-12-19 36/week @ 2023-12-26 5/week @ 2024-01-02 10/week @ 2024-01-09 8/week @ 2024-01-16 22/week @ 2024-01-23 31/week @ 2024-01-30 9/week @ 2024-02-06 99/week @ 2024-02-13

162 downloads per month
Used in dvm

MIT license

11KB
173 lines

set_env

This crate allows you to permanently set environment variables

Based on env_perm

Examples

// Check if DUMMY is set, if not set it to 1
// export DUMMY=1
set_env::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"Cancel changes
set_env::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"
set_env::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.

On windows, this crate will modify the HKEY_CURRENT_USER\Environment registry items

Dependencies

~56–530KB