aboutsummaryrefslogtreecommitdiff
path: root/src/venv.rs
blob: da6830cdca640325d2387e8dded95194482777fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use std::env;
use colored::*;
use std::path::Path;

pub fn get_name() -> colored::ColoredString {
    match env::var("VIRTUAL_ENV") {
        Ok(venv_path) => {
            let venv_name = Path::new(&venv_path[..]).file_name();
            if let Some(name) = venv_name {
                if let Some(valid_name) = name.to_str() {
                    return format!("({})", valid_name).bright_black();
                }
            }
        }
        Err(_) => {}
    }
    return "".white()
}

pub fn in_nix_shell() -> colored::ColoredString {
    match env::var("IN_NIX_SHELL") {
        Ok(p) => {
            if p == "pure" {
                "(nix) ".green()
            } else {
                "(nix) ".red()
            }
        }
        _ => return "".white(),
    }
}