Skip to content

Commit

Permalink
add direct PATH support
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmmetz committed Sep 26, 2022
1 parent 41b8c5d commit 7bdc5df
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

set -euo pipefail

version=0.0.8 # TODO integrate with releases.
version=0.0.9 # TODO integrate with releases.

settle_base=$(pwd)

Expand Down
29 changes: 24 additions & 5 deletions zsh.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"path/filepath"
"strconv"
"strings"

"github.com/go-git/go-git/v5"
Expand All @@ -19,11 +20,12 @@ type Zsh struct {
IgnoreAllDups bool `json:"ignore_all_dups"`
IgnoreSpace bool `json:"ignore_space"`
} `json:"history"`
Variables []KV `json:"variables"`
Aliases []KV `json:"aliases"`
Functions []KV `json:"functions"`
ExtraPrefix string `json:"extra_prefix"`
ExtraSuffix string `json:"extra_suffix"`
Paths []string `json:"paths"`
Variables []KV `json:"variables"`
Aliases []KV `json:"aliases"`
Functions []KV `json:"functions"`
ExtraPrefix string `json:"extra_prefix"`
ExtraSuffix string `json:"extra_suffix"`
}

type KV struct {
Expand Down Expand Up @@ -113,6 +115,14 @@ func (z *Zsh) String() string {
}
sb.WriteString("\n")

// path
if len(z.Paths) > 0 {
if !contains(z.Paths, "$PATH") {
z.Paths = append(z.Paths, "$PATH")
}
sb.WriteString(fmt.Sprintf("export PATH=%s\n", strconv.Quote(strings.Join(z.Paths, ":"))))
}

// variables
for _, kv := range z.Variables {
sb.WriteString(fmt.Sprintf("export %s=%s\n", kv.Name, kv.Value))
Expand Down Expand Up @@ -140,3 +150,12 @@ func (z *Zsh) String() string {
sb.WriteString("\n")
return sb.String()
}

func contains(haystack []string, needle string) bool {
for _, hay := range haystack {
if hay == needle {
return true
}
}
return false
}

0 comments on commit 7bdc5df

Please sign in to comment.