5
5
"fmt"
6
6
"os"
7
7
"path/filepath"
8
+ "strconv"
8
9
"strings"
9
10
10
11
"github.com/go-git/go-git/v5"
@@ -19,11 +20,12 @@ type Zsh struct {
19
20
IgnoreAllDups bool `json:"ignore_all_dups"`
20
21
IgnoreSpace bool `json:"ignore_space"`
21
22
} `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"`
27
29
}
28
30
29
31
type KV struct {
@@ -113,6 +115,14 @@ func (z *Zsh) String() string {
113
115
}
114
116
sb .WriteString ("\n " )
115
117
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
+
116
126
// variables
117
127
for _ , kv := range z .Variables {
118
128
sb .WriteString (fmt .Sprintf ("export %s=%s\n " , kv .Name , kv .Value ))
@@ -140,3 +150,12 @@ func (z *Zsh) String() string {
140
150
sb .WriteString ("\n " )
141
151
return sb .String ()
142
152
}
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