Skip to content

Commit 1377a52

Browse files
committed
Shorten full paths for jars on nix
1 parent db28f17 commit 1377a52

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

src/procs.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ fn java_ps_name(proc_name_pre: &ProcNamePre) -> Option<String> {
105105
if arg == "-jar" {
106106
ControlFlow::Break(
107107
next.filter(|jar| jar.ends_with(".jar") || jar.ends_with(".war"))
108-
.map(|s| s.to_owned()),
108+
.map(shorten_nix_paths),
109109
)
110110
} else {
111111
ControlFlow::Continue(())
@@ -359,6 +359,19 @@ pub fn ourself() -> Result<Process> {
359359
Ok(procfs::process::Process::myself()?)
360360
}
361361

362+
// more nix special casing:
363+
// jars seem to be likely to have un-informative names,
364+
// so I'd like to print whatever is available,
365+
// except for full paths on nix, those are long.
366+
pub fn shorten_nix_paths(path: &str) -> String {
367+
let pfx = "/nix/store/";
368+
let dash = path.find('-');
369+
match (path.starts_with(pfx), dash) {
370+
(false, _) | (_, None) => path.into(),
371+
(true, Some(dash)) => format!("{}…{}", &path[..pfx.len() + 4], &path[dash..]),
372+
}
373+
}
374+
362375
#[cfg(test)]
363376
mod test {
364377
use super::ProcNamePre;

0 commit comments

Comments
 (0)