~kmaasrud/prompt

f3f59f8a9ed005b2fbc0888f1843a58171427ee3 — kmaasrud 1 year, 6 months ago a1be823
compile nix only on unix and clean code a bit
2 files changed, 13 insertions(+), 9 deletions(-)

M src/cwd.rs
M src/main.rs
M src/cwd.rs => src/cwd.rs +3 -2
@@ 1,10 1,11 @@
use std::env::{current_dir, var_os};
use std::io::{Error, Write};
use std::path::Path;

pub fn cwd<W: Write>(mut w: W) -> Result<(), Error> {
    if let Ok(mut cwd) = std::env::current_dir() {
    if let Ok(mut cwd) = current_dir() {
        cwd = cwd.canonicalize()?;
        if let Some(home) = std::env::var_os("HOME") {
        if let Some(home) = var_os("HOME") {
            if let Ok(stripped) = cwd.strip_prefix(home) {
                cwd = Path::new("~").join(stripped);
            }

M src/main.rs => src/main.rs +10 -7
@@ 3,17 3,20 @@
mod cwd;
mod git;
mod icon;
#[cfg(target_family = "unix")]
mod nix;

use std::io::BufWriter;
use std::io::{Error, Write};
use std::io::{stdout, BufWriter, Error, Write};

fn main() -> Result<(), Error> {
    let mut stdout = BufWriter::new(std::io::stdout().lock());

    faint(&mut stdout)?;
    nix::nix(&mut stdout)?;
    reset(&mut stdout)?;
    let mut stdout = BufWriter::new(stdout().lock());

    #[cfg(target_family = "unix")]
    {
        faint(&mut stdout)?;
        nix::nix(&mut stdout)?;
        reset(&mut stdout)?;
    }

    cwd::cwd(&mut stdout)?;