diff --git a/src/main.rs b/src/main.rs index 5c385f5..e66ca52 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ mod system; fn main() { - println!("{}", system::host::get_uptime()) + println!("{}", system::host::get_shell()); } diff --git a/src/system/host.rs b/src/system/host.rs index c6f0f6c..0076ca2 100644 --- a/src/system/host.rs +++ b/src/system/host.rs @@ -21,7 +21,9 @@ pub fn get_user() -> String { .stdout .iter() .map(|&c| c as char) - .collect() + .collect::() + .trim() + .to_string() } #[cfg(target_os = "linux")] @@ -74,4 +76,25 @@ pub fn get_uptime() -> String { let seconds = uptime % 60; format!("{}d {}h {}m {}s", days, hours, minutes, seconds) +} + +#[cfg(target_os = "linux")] +pub fn get_shell() -> String { + let mut final_str = String::new(); + let mut temp_buf: String = String::new(); + + let mut f = File::open("/etc/passwd").unwrap(); + f.read_to_string(&mut temp_buf).unwrap(); + + let lines: &Vec<&str> = &temp_buf.lines().collect(); + + lines.into_iter().for_each(|line| { + if line.contains(&get_user()) { + final_str = line.split(":") + .collect::>()[6] + .to_string(); + } + }); + + final_str } \ No newline at end of file