snm_core/shell/
zsh.rs

1use super::Shell;
2use std::path::Path;
3
4#[derive(Debug)]
5pub struct Zsh;
6
7impl Shell for Zsh {
8    fn path(&self, path: &Path, append: bool) -> String {
9        if append {
10            return format!("export PATH=$PATH:{:?};", path.display());
11        }
12
13        format!("export PATH={:?}:$PATH;", path.display())
14    }
15
16    fn env_var(&self, name: &str, val: &str) -> String {
17        format!("export {}={:?};", name, val)
18    }
19
20    fn use_on_cd(&self) -> &'static str {
21        indoc::indoc!(
22            r#"
23                autoload -U add-zsh-hook
24                _snm_autoload_hook () {
25                    if [[ -f .node-version || -f .nvmrc || -f package.json ]]; then
26                        snm use
27                    fi
28                }
29                add-zsh-hook -Uz chpwd _snm_autoload_hook
30            "#
31        )
32    }
33}