Skip to content

Commit 7bdc5df

Browse files
committed
add direct PATH support
1 parent 41b8c5d commit 7bdc5df

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
set -euo pipefail
2929

30-
version=0.0.8 # TODO integrate with releases.
30+
version=0.0.9 # TODO integrate with releases.
3131

3232
settle_base=$(pwd)
3333

zsh.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"os"
77
"path/filepath"
8+
"strconv"
89
"strings"
910

1011
"github.com/go-git/go-git/v5"
@@ -19,11 +20,12 @@ type Zsh struct {
1920
IgnoreAllDups bool `json:"ignore_all_dups"`
2021
IgnoreSpace bool `json:"ignore_space"`
2122
} `json:"history"`
22-
Variables []KV `json:"variables"`
23-
Aliases []KV `json:"aliases"`
24-
Functions []KV `json:"functions"`
25-
ExtraPrefix string `json:"extra_prefix"`
26-
ExtraSuffix string `json:"extra_suffix"`
23+
Paths []string `json:"paths"`
24+
Variables []KV `json:"variables"`
25+
Aliases []KV `json:"aliases"`
26+
Functions []KV `json:"functions"`
27+
ExtraPrefix string `json:"extra_prefix"`
28+
ExtraSuffix string `json:"extra_suffix"`
2729
}
2830

2931
type KV struct {
@@ -113,6 +115,14 @@ func (z *Zsh) String() string {
113115
}
114116
sb.WriteString("\n")
115117

118+
// path
119+
if len(z.Paths) > 0 {
120+
if !contains(z.Paths, "$PATH") {
121+
z.Paths = append(z.Paths, "$PATH")
122+
}
123+
sb.WriteString(fmt.Sprintf("export PATH=%s\n", strconv.Quote(strings.Join(z.Paths, ":"))))
124+
}
125+
116126
// variables
117127
for _, kv := range z.Variables {
118128
sb.WriteString(fmt.Sprintf("export %s=%s\n", kv.Name, kv.Value))
@@ -140,3 +150,12 @@ func (z *Zsh) String() string {
140150
sb.WriteString("\n")
141151
return sb.String()
142152
}
153+
154+
func contains(haystack []string, needle string) bool {
155+
for _, hay := range haystack {
156+
if hay == needle {
157+
return true
158+
}
159+
}
160+
return false
161+
}

0 commit comments

Comments
 (0)