1use anyhow::Result;
4use std::path::PathBuf;
5
6pub const INSTALL_BASH_FUNCTION: &str = r#"
8function cargo() {
9 if ~/.cargo/bin/cargo hoist --help &>/dev/null; then
10 ~/.cargo/bin/cargo hoist --quiet install
11 fi
12 ~/.cargo/bin/cargo "$@"
13}
14"#;
15
16#[derive(Debug, Clone, Copy, PartialEq, Eq)]
18pub enum ShellType {
19 Zsh,
21 Bash,
23 Other,
25}
26
27pub fn detect_shell() -> Result<ShellType> {
29 if let Ok(shell_path) = std::env::var("SHELL") {
30 if shell_path.contains("zsh") {
31 Ok(ShellType::Zsh)
32 } else if shell_path.contains("bash") {
33 Ok(ShellType::Bash)
34 } else {
35 Ok(ShellType::Other)
36 }
37 } else {
38 Ok(ShellType::Bash)
40 }
42}
43
44pub fn get_shell_config_file(shell_type: ShellType) -> Result<PathBuf> {
46 let home_dir = std::env::var("HOME")?;
47 match shell_type {
48 ShellType::Zsh => Ok(PathBuf::from(format!("{}/.zshrc", home_dir))),
49 _ => Ok(PathBuf::from(format!("{}/.bashrc", home_dir))),
50 }
51}