Fix ps command to show process name only (#4544)

* Fix `ps` command to show process name only

* Remove `command_only` -  it is no longer being used
This commit is contained in:
Joseph T. Lyons 2022-02-18 20:48:52 -05:00 committed by GitHub
parent da42100374
commit 3ecf17e7af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -303,20 +303,15 @@ impl ProcessInfo {
/// Name of command /// Name of command
pub fn name(&self) -> String { pub fn name(&self) -> String {
// self.command()
// .split(' ')
// .collect::<Vec<_>>()
// .first()
// .map(|x| x.to_string())
// .unwrap_or_default()
self.command_only()
}
/// Full name of command, with arguments
pub fn command(&self) -> String {
if let Some(path) = &self.curr_path { if let Some(path) = &self.curr_path {
if !path.cmd.is_empty() { if !path.cmd.is_empty() {
path.cmd.join(" ").replace("\n", " ").replace("\t", " ") let command_path = &path.exe;
if let Some(command_name) = command_path.file_name() {
command_name.to_string_lossy().to_string()
} else {
command_path.to_string_lossy().to_string()
}
} else { } else {
String::from("") String::from("")
} }
@ -325,11 +320,11 @@ impl ProcessInfo {
} }
} }
/// Full name of comand only /// Full name of command, with arguments
pub fn command_only(&self) -> String { pub fn command(&self) -> String {
if let Some(path) = &self.curr_path { if let Some(path) = &self.curr_path {
if !path.cmd.is_empty() { if !path.cmd.is_empty() {
path.exe.to_string_lossy().to_string() path.cmd.join(" ").replace("\n", " ").replace("\t", " ")
} else { } else {
String::from("") String::from("")
} }