Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
- Supports POSIX compliant shells like Bash and ZSH, but now also Fish :)

## Quick start

Expand Down
38 changes: 37 additions & 1 deletion init.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io/ioutil"
"os"
"os/user"
"path"
"path/filepath"
"text/template"
)
Expand Down Expand Up @@ -42,6 +43,36 @@ 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
set -e GOENV_OLDPS1
set -e GOENV_OLDPATH
set -e GOENV_OLDGOPATH
functions --erase deactivate
end
`

var initCommand = Command{
Name: "init",
Short: "initialize a goenv",
Expand Down Expand Up @@ -152,6 +183,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)

Expand All @@ -160,7 +192,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
Expand Down