mirror of
https://github.com/nushell/nushell.git
synced 2025-08-16 17:31:39 +02:00
Ps: add cwd
column on linux and macos (#10347)
# Description Close: #7484 Just found that I want `cwd` column on linux/macos as well..
This commit is contained in:
@ -142,6 +142,7 @@ pub struct PathInfo {
|
||||
pub root: PathBuf,
|
||||
pub cmd: Vec<String>,
|
||||
pub env: Vec<String>,
|
||||
pub cwd: PathBuf,
|
||||
}
|
||||
|
||||
#[cfg_attr(tarpaulin, skip)]
|
||||
@ -213,12 +214,17 @@ fn get_path_info(pid: i32, mut size: size_t) -> Option<PathInfo> {
|
||||
}
|
||||
start = cp;
|
||||
let mut env = Vec::new();
|
||||
let mut cwd = PathBuf::default();
|
||||
while cp < ptr.add(size) {
|
||||
if *cp == 0 {
|
||||
if cp == start {
|
||||
break;
|
||||
}
|
||||
env.push(get_unchecked_str(cp, start));
|
||||
let env_str = get_unchecked_str(cp, start);
|
||||
if let Some(pwd) = env_str.strip_prefix("PWD=") {
|
||||
cwd = PathBuf::from(pwd)
|
||||
}
|
||||
env.push(env_str);
|
||||
start = cp.offset(1);
|
||||
}
|
||||
cp = cp.offset(1);
|
||||
@ -238,6 +244,7 @@ fn get_path_info(pid: i32, mut size: size_t) -> Option<PathInfo> {
|
||||
root,
|
||||
cmd,
|
||||
env,
|
||||
cwd,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
@ -394,6 +401,13 @@ impl ProcessInfo {
|
||||
pub fn virtual_size(&self) -> u64 {
|
||||
self.curr_task.ptinfo.pti_virtual_size
|
||||
}
|
||||
|
||||
pub fn cwd(&self) -> String {
|
||||
self.curr_path
|
||||
.as_ref()
|
||||
.map(|cur_path| cur_path.cwd.display().to_string())
|
||||
.unwrap_or_else(|| "".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
/// The Macos kernel returns process times in mach ticks rather than nanoseconds. To get times in
|
||||
|
Reference in New Issue
Block a user