diff --git a/src/context/os.go b/src/context/os.go new file mode 100644 index 0000000..5bc2dac --- /dev/null +++ b/src/context/os.go @@ -0,0 +1,7 @@ +package context + +const ( + WINDOWS = "windows" + LINUX = "linux" + DARWIN = "darwin" +) diff --git a/src/shell/aliae_test.go b/src/shell/aliae_test.go index 8f84e58..46850bf 100644 --- a/src/shell/aliae_test.go +++ b/src/shell/aliae_test.go @@ -219,7 +219,7 @@ func TestAliasWithTemplate(t *testing.T) { for _, tc := range cases { alias := &Alias{Name: "a", Value: tc.Value} - context.Current = &context.Runtime{Shell: BASH, Home: "/Users/jan", OS: "windows"} + context.Current = &context.Runtime{Shell: BASH, Home: "/Users/jan", OS: context.WINDOWS} assert.Equal(t, tc.Expected, alias.string(), tc.Case) } } diff --git a/src/shell/nu.go b/src/shell/nu.go index 98305d9..9424394 100644 --- a/src/shell/nu.go +++ b/src/shell/nu.go @@ -1,6 +1,7 @@ package shell import ( + "fmt" "os" "path/filepath" @@ -37,7 +38,14 @@ func (e *Env) nu() *Env { } func (p *Path) nu() *Path { - p.template = `let-env PATH = ($env.PATH | prepend "{{ .Value }}")` + template := `$env.%s = ($env.%s | prepend "{{ .Value }}")` + pathName := "PATH" + + if context.Current.OS == context.WINDOWS { + pathName = "Path" + } + + p.template = fmt.Sprintf(template, pathName, pathName) return p } diff --git a/src/shell/path_test.go b/src/shell/path_test.go index 1b669d4..8c37b5c 100644 --- a/src/shell/path_test.go +++ b/src/shell/path_test.go @@ -12,6 +12,7 @@ func TestPath(t *testing.T) { Case string Shell string Path *Path + OS string Expected string }{ { @@ -75,14 +76,22 @@ fish_add_path /usr/bin`, Case: "NU - single item", Shell: NU, Path: &Path{Value: "/usr/local/bin"}, - Expected: `let-env PATH = ($env.PATH | prepend "/usr/local/bin")`, + Expected: `$env.PATH = ($env.PATH | prepend "/usr/local/bin")`, }, { Case: "NU - multiple items", Shell: NU, Path: &Path{Value: "/usr/local/bin\n/usr/bin"}, - Expected: `let-env PATH = ($env.PATH | prepend "/usr/local/bin") -let-env PATH = ($env.PATH | prepend "/usr/bin")`, + Expected: `$env.PATH = ($env.PATH | prepend "/usr/local/bin") +$env.PATH = ($env.PATH | prepend "/usr/bin")`, + }, + { + Case: "NU - Windows", + Shell: NU, + OS: context.WINDOWS, + Path: &Path{Value: "/usr/local/bin\n/usr/bin"}, + Expected: `$env.Path = ($env.Path | prepend "/usr/local/bin") +$env.Path = ($env.Path | prepend "/usr/bin")`, }, { Case: "TCSH - single item", @@ -126,7 +135,7 @@ export PATH="/usr/bin:$PATH"`, } for _, tc := range cases { - context.Current = &context.Runtime{Shell: tc.Shell, Home: "/Users/jan"} + context.Current = &context.Runtime{Shell: tc.Shell, Home: "/Users/jan", OS: tc.OS} assert.Equal(t, tc.Expected, tc.Path.string(), tc.Case) } }