mirror of
https://github.com/Atsukoro1/ponyfetch.git
synced 2024-11-23 20:57:59 +01:00
feat: 🎸 get shell
This commit is contained in:
parent
e0a139151f
commit
028330ab92
2 changed files with 25 additions and 2 deletions
|
@ -1,5 +1,5 @@
|
||||||
mod system;
|
mod system;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("{}", system::host::get_uptime())
|
println!("{}", system::host::get_shell());
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,9 @@ pub fn get_user() -> String {
|
||||||
.stdout
|
.stdout
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&c| c as char)
|
.map(|&c| c as char)
|
||||||
.collect()
|
.collect::<String>()
|
||||||
|
.trim()
|
||||||
|
.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
|
@ -75,3 +77,24 @@ pub fn get_uptime() -> String {
|
||||||
|
|
||||||
format!("{}d {}h {}m {}s", days, hours, minutes, seconds)
|
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::<Vec<&str>>()[6]
|
||||||
|
.to_string();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
final_str
|
||||||
|
}
|
Loading…
Reference in a new issue