Skip to main content

easy_install/
env.rs

1use std::path::PathBuf;
2
3use anyhow::{Context, Result};
4use crud_path::{add_github_path, is_github};
5
6pub(crate) fn add_to_path(dir: &str) {
7    let dir = dir.trim_end_matches('/');
8    if crud_path::has_path(dir) {
9        return;
10    }
11
12    if is_github() {
13        add_github_path(dir);
14        println!("Successfully added {dir} to github's $PATH");
15    }
16
17    if let Some(sh) = crud_path::add_path(dir) {
18        println!("Successfully added {dir} to {sh}'s $PATH");
19    } else {
20        println!("You need to add {dir} to your $PATH");
21    }
22}
23
24pub(crate) fn get_install_dir() -> Result<PathBuf> {
25    let mut home = dirs::home_dir().context("Failed to get home_dir")?;
26    home.push(".ei");
27
28    if !home.exists() {
29        std::fs::create_dir_all(&home).context("Failed to create_dir home_dir")?;
30    }
31    Ok(home)
32}