Skip to content

Commit

Permalink
fix(nu): platform dependant PATH name
Browse files Browse the repository at this point in the history
  • Loading branch information
JanDeDobbeleer committed Aug 28, 2023
1 parent d412677 commit 3f8e412
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/context/os.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package context

const (
WINDOWS = "windows"
LINUX = "linux"
DARWIN = "darwin"
)
2 changes: 1 addition & 1 deletion src/shell/aliae_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
10 changes: 9 additions & 1 deletion src/shell/nu.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package shell

import (
"fmt"
"os"
"path/filepath"

Expand Down Expand Up @@ -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
}

Expand Down
17 changes: 13 additions & 4 deletions src/shell/path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ func TestPath(t *testing.T) {
Case string
Shell string
Path *Path
OS string
Expected string
}{
{
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 3f8e412

Please sign in to comment.