Gosh
is the interactive Golang shell.
The goal is to provide an easy-to-use interactive execution environment.
- Interactive shell
- Enable to omit the main function
- Enable to omit package statement
- Enable to omit the import statement of standard library
- Enable to Import libraries of non-standard library
- Enable to re-declare function, type
- Ignoring duplicate import package
- Ignoring unused import package
- Golang >= 1.2
- goimports command
- We recommend that you install
goimports
to$PATH
in advance. - Installing automatically if the command is not found in
$PATH
(>= v0.3.0). - However, the time until the installation is complete in this case,
you will be waiting for the launch of "
Gosh
" process.
- We recommend that you install
Install the follow packages
- golang
- golang-go.tools (recommended)
Set GOPATH
:
$ install -d /path/to/gopath $ export GOPATH=/path/to/gopath
If you install goimports
in advance (recommended),:
$ sudo apt-get install -y golang-go.tools
Install Gosh
to GOPATH
.:
$ go get github.com/mkouhei/gosh
Install the follow packages with Homebrew.
- Go
- Mercurial (with Homebrew)
Set GOPATH
,:
$ install -d /path/to/gopath $ export GOPATH=/path/to/gopath
If you install goimports
in advance (recommend),:
$ export PATH=${GOPATH}/bin:$PATH $ go get code.google.com/p/go.tools/cmd/goimport
Install the Gosh
,:
$ go get github.com/mkouhei/gosh
Examples:
$ $GOPATH/bin/gosh >>> import "fmt" >>> func main() { >>> fmt.Println("hello") >>> } hello >>>
or:
$ $GOPATH/bin/gosh >>> func main() { >>> fmt.Println("hello") >>> } hello >>>
Enable to omit import statement related with standard libraries.
For example of using the some package.:
>>> import "net/http" >>> import "example.org/somepkg" >>> func main() { >>> r, _ := http.Get("http://example.org/some") >>> defer r.Body.Close() >>> p, _ := somepkg.Reader(r.Body) >>> fmt.Println(p) >>> } (print some payload)
Example:
$ $GOPATH/bin/gosh >>> i := 1 >>> i++ >>> fmt.Println(i) 2 >>>
Terminate gosh to reset main declarations, or declare func main without body.:
$ $GOSH/bin/gosh >>> i := i >>> fmt.Println(i) 1 >>> func main() {} >>> fmt.Println(i) [error] # command-line-arguments ./gosh_tmp.go:8: undefined: i >>>
fmt.Print*
are executed only once.
Not evaluate when there are declared and not used valiables.:
$ $GOPATH/bin/gosh >>> i := 1 >>> fmt.Println("hello") >>>
- Tab completion
- Enable to omit import statement of system global installed packages
Gosh
is licensed under GPLv3.