{"id":28200819,"url":"https://github.com/esrlabs/envvars","last_synced_at":"2025-06-12T17:30:58.260Z","repository":{"id":101483376,"uuid":"605725070","full_name":"esrlabs/envvars","owner":"esrlabs","description":null,"archived":false,"fork":false,"pushed_at":"2024-12-19T13:19:18.000Z","size":52,"stargazers_count":2,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-16T21:16:38.108Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/esrlabs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-23T19:12:26.000Z","updated_at":"2024-12-19T13:19:22.000Z","dependencies_parsed_at":null,"dependency_job_id":"5dd7f03f-0afc-4958-88a1-cd2922d61f5a","html_url":"https://github.com/esrlabs/envvars","commit_stats":{"total_commits":13,"total_committers":2,"mean_commits":6.5,"dds":"0.15384615384615385","last_synced_commit":"65dc8d52a8f3d090820c48732d4fc2b1c048a909"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/esrlabs/envvars","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esrlabs%2Fenvvars","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esrlabs%2Fenvvars/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esrlabs%2Fenvvars/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esrlabs%2Fenvvars/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/esrlabs","download_url":"https://codeload.github.com/esrlabs/envvars/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/esrlabs%2Fenvvars/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259511992,"owners_count":22869325,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-05-16T21:17:30.995Z","updated_at":"2025-06-12T17:30:58.254Z","avatar_url":"https://github.com/esrlabs.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# envvars\n\n`envvars` helps to detect a list of available shells and related environment variables. If works in two steps:\n\n- detecting a list of available shells and creating `Profile` for each found shell\n- loading a list of environment variables for selected or each shell\n\n## Usage\n\nGetting all available (detected) shells and related to each shell list of environment variables\n\n``` Rust\nuse envvars::{get_profiles, Profile};\n\n// ...\nlet mut profiles: Vec\u003cProfile\u003e = get_profiles().unwrap();\n\n// By default profile doesn't have loaded list of environment variables.\n// It should be loaded calling method load().\nprofiles.iter_mut().for_each(|profile| {\n    // Attempt to load envvars\n    if let Err(err) = profile.load() {\n        eprintln!(\"Cannot load envvars for {}: {err}\", profile.name);\n    }\n    if let Some(envvars) = \u0026profile.envvars {\n        println!(\"Environment variables for {}\", profile.name);\n        envvars.iter().for_each(|(key, value)| {\n            println!(\"{key}: {value}\");\n        });\n    }\n});\n```\n\nExtract environment variables without shell context.\n\n``` Rust\nuse std::collections::HashMap;\nuse envvars::get_context_envvars;\n\n// ...\nlet vars: HashMap\u003cString, String\u003e = get_context_envvars().unwrap();\n\nassert!(vars.contains_key(\"PATH\") || vars.contains_key(\"Path\") || vars.contains_key(\"path\"));\n```\n\n## Diffrence from `std::env::vars`\n\n`envvars` actually executes each found `shell` it means: all settings of the target shell will be inited before a list of environment variables will be requested. That's very sensitive if the configuration of some shell includes some initialization script, which affects environment variables. That means in some cases `std::env::vars` and `envvars` could give different results.\n \n## How it works\n\nUnder the hood, `envvars` takes each shell, and executes it with a command, which posts a list of environment variables to `stdout`. As soon as executing\nis done, `envvars` reads `stdout` and parse environment variables into `HashMap\u003cString, String\u003e`.\n\nAs soon as extracting process could take a sensitive time (~1sec on windows and ~10ms on Unix-based OS), `envvars` doesn't extract environment variables\nduring detecting the shell's profiles. That's the developer's decision when it should be done for the selected or each profile.\n\n`envvars` creates a small executable application in the system's temporary folder. This application is used to \"drop\" list of environment variables into `stdout` of the parent process and does nothing else. As soon as `envvars` instance is dropped, the application would be removed from the disk.\n\nFor security reasons `envvars` checks the checksum of the extractor each time before using it. If a checksum is invalid (the file was damaged/changed etc),\n`envars` will remove a corrupted file and create a new one.\n\n## Unix specific\n\n`envvars` reads `/etc/shells` and analyze each shell from a list\n\n## Windows specific\n\n`envvars` checks for availability next shells:\n- Command Prompt\n- Windows PowerShell\n- .NET Core PowerShell Global Tool\n- Cygwin x64\n- Cygwin\n- bash (MSYS2)\n- GitBash\n\n## Guaranteed results\n\nBecause `envvars` tries to initialize each shell and \"drop\" a list of environment variables to `stdout`, the shell should support the possibility to put a command as an argument, for example: `/bin/bash -c path_to_command`. Obviously not many, but still some shells don't support it (like windows command prompt). In this case, you still can use `get_context_envvars()` to get a list of environment variables without the shell's context.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fesrlabs%2Fenvvars","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fesrlabs%2Fenvvars","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fesrlabs%2Fenvvars/lists"}