From 4142936f657004f88e259583136f25f566b0b1c0 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 3 Jan 2022 05:33:21 -0500 Subject: split up code into more files --- src/env.rs | 48 ++++++++++++++++-------------------------------- 1 file changed, 16 insertions(+), 32 deletions(-) (limited to 'src/env.rs') diff --git a/src/env.rs b/src/env.rs index 3ff2576..e88ec7c 100644 --- a/src/env.rs +++ b/src/env.rs @@ -1,40 +1,24 @@ -pub fn pwd() -> anyhow::Result { - let mut pwd = std::env::current_dir()?.display().to_string(); - if let Ok(home) = std::env::var("HOME") { - if pwd.starts_with(&home) { - pwd.replace_range(..home.len(), "~"); - } - } - Ok(pwd) -} +use std::os::unix::process::ExitStatusExt as _; -pub fn user() -> anyhow::Result { - Ok(users::get_current_username() - .ok_or_else(|| anyhow::anyhow!("couldn't get username"))? - .to_string_lossy() - .into_owned()) +#[derive(Clone)] +pub struct Env { + latest_status: async_std::process::ExitStatus, } -#[allow(clippy::unnecessary_wraps)] -pub fn prompt_char() -> anyhow::Result { - if users::get_current_uid() == 0 { - Ok("#".into()) - } else { - Ok("$".into()) +impl Env { + pub fn new(code: i32) -> Self { + Self { + latest_status: async_std::process::ExitStatus::from_raw( + code << 8, + ), + } } -} -pub fn hostname() -> anyhow::Result { - let mut hostname = hostname::get()?.to_string_lossy().into_owned(); - if let Some(idx) = hostname.find('.') { - hostname.truncate(idx); + pub fn set_status(&mut self, status: async_std::process::ExitStatus) { + self.latest_status = status; } - Ok(hostname) -} -#[allow(clippy::unnecessary_wraps)] -pub fn time(offset: time::UtcOffset) -> anyhow::Result { - Ok(crate::format::time( - time::OffsetDateTime::now_utc().to_offset(offset), - )) + pub fn latest_status(&self) -> &async_std::process::ExitStatus { + &self.latest_status + } } -- cgit v1.2.3-54-g00ecf