From 7bdc5dff3f8d9a695e03457a140348ef46e3c835 Mon Sep 17 00:00:00 2001 From: Daniel Metz Date: Mon, 26 Sep 2022 11:31:26 -0400 Subject: [PATCH] add direct PATH support --- install.sh | 2 +- zsh.go | 29 ++++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/install.sh b/install.sh index 1120ab0..cb8cc5f 100755 --- a/install.sh +++ b/install.sh @@ -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) diff --git a/zsh.go b/zsh.go index 49396cc..3898e16 100644 --- a/zsh.go +++ b/zsh.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "path/filepath" + "strconv" "strings" "github.com/go-git/go-git/v5" @@ -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 { @@ -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)) @@ -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 +}