nushell/src/commands/ps.rs

18 lines
583 B
Rust
Raw Normal View History

2019-05-10 18:59:12 +02:00
use crate::errors::ShellError;
use crate::object::process::process_dict;
use crate::prelude::*;
use sysinfo::{RefreshKind, SystemExt};
2019-05-10 18:59:12 +02:00
2019-07-24 06:10:48 +02:00
pub fn ps(args: CommandArgs, _registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
let mut system = sysinfo::System::new_with_specifics(RefreshKind::new().with_processes());
system.refresh_processes();
2019-05-22 09:12:03 +02:00
let list = system.get_process_list();
2019-05-10 18:59:12 +02:00
2019-05-22 09:12:03 +02:00
let list = list
.into_iter()
2019-07-24 00:22:11 +02:00
.map(|(_, process)| process_dict(process, args.name_span()))
2019-05-22 09:12:03 +02:00
.collect::<VecDeque<_>>();
2019-05-10 18:59:12 +02:00
Ok(list.from_input_stream())
2019-05-10 18:59:12 +02:00
}