pub struct Profile {
pub name: String,
pub path: PathBuf,
pub envvars: Option<HashMap<String, String>>,
pub symlink: bool,
/* private fields */
}
Expand description
Definition of shell profile
Fields§
§name: String
Suggested name of shell. For unix based systems it will be name of executable file, like “bash”, “fish” etc. For windows it will be names like “GitBash”, “PowerShell” etc.
path: PathBuf
Path to executable file of shell
envvars: Option<HashMap<String, String>>
List of environment variables. Because extracting operation could take some time
by default envvars = None
. To load data should be used method load
, which will
make attempt to detect environment variables.
symlink: bool
true - if path to executable file of shell is symlink to another location.
Implementations§
source§impl Profile
impl Profile
sourcepub fn new(
shell: &PathBuf,
args: Vec<&str>,
name: Option<&str>
) -> Result<Self, Error>
pub fn new( shell: &PathBuf, args: Vec<&str>, name: Option<&str> ) -> Result<Self, Error>
Creates shell’s profile description
shell
- path to shell’s executable fileargs
- list of arguments needed to pass a command into shell. For example: “-c” to have a full command like: “/etc/bin/bash -c cmd”name
- optional name for profile. For unix based systems it will be name of executable file, like “bash”, “fish” etc. For windows better to provide name to have it like “GitBash”, “PowerShell” etc.
sourcepub fn load(&mut self) -> Result<(), Error>
pub fn load(&mut self) -> Result<(), Error>
Makes attempt to grab a list of environment variables for profile. It will
spawn an instance of shell with extractor as command argument. If stdout will
have suitable output, it will be parsed and list of environment variables will
be saved in self.envvars
§Examples
use std::{path::PathBuf, str::FromStr};
use envvars::Profile;
let mut profile: Profile = if cfg!(windows) {
Profile::new(&PathBuf::from_str("C:\\Program Files\\Git\\bin\\bash.exe").unwrap(), vec!["-c"], None).unwrap()
} else {
Profile::new(&PathBuf::from_str("/bin/bash").unwrap(), vec!["-c"], None).unwrap()
};
assert_eq!(profile.name, if cfg!(windows) {
"bash.exe"
} else {
"bash"
});
profile.load().unwrap();
assert!(profile.envvars.is_some());
if let Some(vars) = profile.envvars.as_ref() {
assert!(vars.contains_key("PATH") || vars.contains_key("Path") || vars.contains_key("path"));
}