1use super::Shell;
2use std::path::Path;
3
4#[derive(Debug)]
5pub struct Pwsh;
6
7impl Shell for Pwsh {
8 fn path(&self, path: &Path, append: bool) -> String {
9 let path_env = std::env::var_os("PATH").unwrap_or_default();
10 let mut split_paths: Vec<_> = std::env::split_paths(&path_env).collect();
11
12 if append {
13 split_paths.push(path.to_path_buf());
14 } else {
15 split_paths.insert(0, path.to_path_buf());
16 }
17
18 let new_path = std::env::join_paths(split_paths).expect("Can't join paths");
19 self.env_var("PATH", new_path.to_str().expect("Can't read PATH"))
20 }
21
22 fn env_var(&self, name: &str, val: &str) -> String {
23 format!(r#"$env:{} = "{}""#, name, val)
24 }
25
26 fn use_on_cd(&self) -> &'static str {
27 indoc::indoc!(
28 r#"
29 function Set-LocationWithSnm { param($path); Set-Location $path; If ((Test-Path .nvmrc) -Or (Test-Path .node-version) -Or (Test-Path package.json)) { & snm use } }
30 Set-Alias cd_with_snm Set-LocationWithSnm -Force
31 Remove-Item alias:\cd
32 New-Alias cd Set-LocationWithSnm
33 "#
34 )
35 }
36}