summaryrefslogtreecommitdiffstats
path: root/src/format.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2022-01-03 23:12:08 -0500
committerJesse Luehrs <doy@tozt.net>2022-01-03 23:12:08 -0500
commit1a281c87758ca559b4353fbd166dcd8e92a97f3a (patch)
tree32a01ce3487c98cafb325ab49fceff566a1a3d30 /src/format.rs
parent10717b2b1f29a1b35742ae0cb98e775ac55e248c (diff)
downloadnbsh-1a281c87758ca559b4353fbd166dcd8e92a97f3a.tar.gz
nbsh-1a281c87758ca559b4353fbd166dcd8e92a97f3a.zip
propagate current directory changes back to the main process
Diffstat (limited to 'src/format.rs')
-rw-r--r--src/format.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/format.rs b/src/format.rs
index 1560439..f2414cc 100644
--- a/src/format.rs
+++ b/src/format.rs
@@ -1,5 +1,15 @@
use std::os::unix::process::ExitStatusExt as _;
+pub fn path(path: &std::path::Path) -> String {
+ let mut path = path.display().to_string();
+ if let Ok(home) = std::env::var("HOME") {
+ if path.starts_with(&home) {
+ path.replace_range(..home.len(), "~");
+ }
+ }
+ path
+}
+
pub fn exit_status(status: std::process::ExitStatus) -> String {
status.signal().map_or_else(
|| format!("{:03} ", status.code().unwrap()),