From 1c294222e0de1cfc693ec1c9b60e6ba1a8b1da6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20S=C3=B8rensen?= Date: Sun, 7 Jan 2018 15:37:27 +0100 Subject: [PATCH 1/5] Add fish initialization script template --- init.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/init.go b/init.go index c9363b9..2be5c93 100644 --- a/init.go +++ b/init.go @@ -42,6 +42,34 @@ deactivate() { } ` +const scriptFish = ` +# This file must be used with "source activate" or ". activate" + +if test -n "$GOENV" + deactivate +end + +set -x GOENV {{.ProjectName}} +set -x GOENV_OLDGOPATH $GOPATH +set -x GOENV_OLDPATH $PATH + +set -x GOPATH {{.GoPath}} +set -x PATH $GOPATH/bin $PATH + +mkdir -p $(dirname $GOPATH/src/{{.ImportPath}}) +rm -f $GOPATH/src/{{.ImportPath}} +ln -s {{.ProjectPath}} $GOPATH/src/{{.ImportPath}} + +function deactivate + set -x GOPATH $GOENV_OLDGOPATH + set -x PATH $GOENV_OLDPATH + + set -e GOENV GOENV_OLDPS1 GOENV_OLDPATH GOENV_OLDGOPATH + functions --erase deactivate +end +funcsave deactivate +` + var initCommand = Command{ Name: "init", Short: "initialize a goenv", From a44ae36fb01094f55fac8b5bd61092658fcde034 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20S=C3=B8rensen?= Date: Sun, 7 Jan 2018 15:44:54 +0100 Subject: [PATCH 2/5] Parse fish script on fish shell --- init.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/init.go b/init.go index 2be5c93..429317c 100644 --- a/init.go +++ b/init.go @@ -8,6 +8,7 @@ import ( "io/ioutil" "os" "os/user" + "path" "path/filepath" "text/template" ) @@ -180,6 +181,7 @@ func (task *InitTask) Run() error { // writeScript writes the goenv activate script. func (task *InitTask) writeScript() error { + var isFish = path.Base(os.Getenv("SHELL")) == "fish" err := os.MkdirAll(filepath.Dir(task.ScriptPath), os.ModeDir|0755) @@ -188,7 +190,11 @@ func (task *InitTask) writeScript() error { } scriptTemplate := template.New("test") - scriptTemplate, err = scriptTemplate.Parse(script) + if isFish { + scriptTemplate, err = scriptTemplate.Parse(scriptFish) + } else { + scriptTemplate, err = scriptTemplate.Parse(script) + } if err != nil { return err From 04e2a0ab5317692125a5691731e914cc08888ef9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20S=C3=B8rensen?= Date: Sun, 7 Jan 2018 16:58:55 +0100 Subject: [PATCH 3/5] Patch up init script template to make Fish happy --- init.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/init.go b/init.go index 429317c..bb141cb 100644 --- a/init.go +++ b/init.go @@ -57,7 +57,7 @@ set -x GOENV_OLDPATH $PATH set -x GOPATH {{.GoPath}} set -x PATH $GOPATH/bin $PATH -mkdir -p $(dirname $GOPATH/src/{{.ImportPath}}) +mkdir -p (dirname $GOPATH/src/{{.ImportPath}}) rm -f $GOPATH/src/{{.ImportPath}} ln -s {{.ProjectPath}} $GOPATH/src/{{.ImportPath}} @@ -65,10 +65,12 @@ function deactivate set -x GOPATH $GOENV_OLDGOPATH set -x PATH $GOENV_OLDPATH - set -e GOENV GOENV_OLDPS1 GOENV_OLDPATH GOENV_OLDGOPATH + set -e GOENV + set -e GOENV_OLDPS1 + set -e GOENV_OLDPATH + set -e GOENV_OLDGOPATH functions --erase deactivate end -funcsave deactivate ` var initCommand = Command{ From 75a8f65e39c68ff324e36d542281c8d1b87d0a73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20S=C3=B8rensen?= Date: Sun, 7 Jan 2018 17:01:44 +0100 Subject: [PATCH 4/5] Update readme to reflect Fish support --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 352f4ca..ec15904 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ Go's package management expects that all go source files and packages will exist - Isolates dependencies from other projects. - Does not interfere with any `go` command functionality. - Written in Go, installable with `go get`. +- Support POSIX compliant shells like Bash and ZSH, but now also Fish :) ## Quick start From a1711fc723155b102696c4cd19fa9de440f0ada3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20S=C3=B8rensen?= Date: Sun, 7 Jan 2018 17:02:56 +0100 Subject: [PATCH 5/5] Fix rypo in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ec15904..df1c95b 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Go's package management expects that all go source files and packages will exist - Isolates dependencies from other projects. - Does not interfere with any `go` command functionality. - Written in Go, installable with `go get`. -- Support POSIX compliant shells like Bash and ZSH, but now also Fish :) +- Supports POSIX compliant shells like Bash and ZSH, but now also Fish :) ## Quick start