#windows #env-var #env #environment #registry

bin+lib windows-env

Easily manage Windows environment variables permanently

2 releases

0.1.1 Oct 13, 2024
0.1.0 Oct 12, 2024

#516 in Operating systems

Download history 1/week @ 2024-11-12 273/week @ 2024-11-19 152/week @ 2024-11-26 105/week @ 2024-12-03 48/week @ 2024-12-10 105/week @ 2024-12-17 62/week @ 2024-12-24 14/week @ 2024-12-31 71/week @ 2025-01-07 2/week @ 2025-01-14 79/week @ 2025-01-21 164/week @ 2025-01-28 85/week @ 2025-02-04

342 downloads per month
Used in bestool

MIT license

14KB
230 lines

windows-env

Easily manage Windows environment variables permanently, without the need to restart your system.

Features:

  • Concurrent safe.
  • Easily operate list variables like PATH.

Note:

  • The env operation will not affect the current terminal.

Installation

  • as lib:
    [target."cfg(windows)".dependencies]
    windows_env = "0.1.1"
    
  • as executable binary:
    cargo binstall windows-env        # see cargo-binstall: https://github.com/cargo-bins/cargo-binstall
    cargo install windows-env -F bin  # or compile from source manually
    

Example

lib usage:

fn main() -> std::io::Result<()> {
    windows_env::set("TEST_ENV", "test")?;
    assert_eq!(windows_env::get("TEST_ENV")?.unwrap(), "test");
    windows_env::remove("TEST_ENV")?;
    assert!(windows_env::get("TEST_ENV")?.is_none());

    windows_env::append("TEST_ENV", "test1")?;
    windows_env::prepend("TEST_ENV", "test2")?;
    assert_eq!(windows_env::get("TEST_ENV")?.unwrap(), "test2;test1");

    windows_env::remove_from_list("TEST_ENV", "test2")?;
    assert!(windows_env::exists_in_list("TEST_ENV", "test1")?);

    windows_env::remove("TEST_ENV")?;
    Ok(())
}

executable binary: runs wenv -h to see help message.

Compare

  • set_env:
    • it uses powershell script while this crate uses windows api

TODO

  • cli support
  • System env modification

Dependencies

~141MB
~2M SLoC