From 3ecf17e7afad01491bbd1a63e8c651d38822ac37 Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Fri, 18 Feb 2022 20:48:52 -0500 Subject: [PATCH] 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 --- crates/nu-system/src/macos.rs | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/crates/nu-system/src/macos.rs b/crates/nu-system/src/macos.rs index 1d1839832b..cf33ae1847 100644 --- a/crates/nu-system/src/macos.rs +++ b/crates/nu-system/src/macos.rs @@ -303,20 +303,15 @@ impl ProcessInfo { /// Name of command pub fn name(&self) -> String { - // self.command() - // .split(' ') - // .collect::>() - // .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 !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 { String::from("") } @@ -325,11 +320,11 @@ impl ProcessInfo { } } - /// Full name of comand only - pub fn command_only(&self) -> String { + /// Full name of command, with arguments + pub fn command(&self) -> String { if let Some(path) = &self.curr_path { if !path.cmd.is_empty() { - path.exe.to_string_lossy().to_string() + path.cmd.join(" ").replace("\n", " ").replace("\t", " ") } else { String::from("") }