Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
goto is a smart cd command for the Go programming language.
Go
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
.gitignore
LICENSE
README.org
doc.go
filesource.go
gosource.go
goto.bash
main.go
source.go

README.org

goto

goto (aka goto-cmd) is is a smart cd command for the Go programming language. It’s inspired by roscd and allows you to cd into a directory using the Go import path. It reflects the $GOROOT and $GOPATH of the environment it’s run in, so if you’re using gvm with different go versions in different terminals, it will go act appropriately.

In addition to the going to go import paths, you can add additional shortcuts in the ~/.goto file, as described below. These can be related to Go or completely unrelated.

Installation

$ go install github.com/alexhenning/goto-cmd

Run the following command, in order for it to persist, add it to your .bashrc:

source $(goto-cmd github.com/alexhenning/goto-cmd)/goto.bash

Add shortcuts [Optional]

Create a file ~/.goto. The format for the ~/.goto file is a pair of labels and corresponding paths. Blank lines and lines beginning with # are ignored.

Example:

# label path

~go     ~/Dropbox/Programming/go
me      ~/Dropbox/Programming/go/src/github.com/alexhenning

# Unrelated to go, just a shortcut
school  ~/Dropbox/School

Usage

The following examples show how to use the goto command, it’s pretty straightforward.

To cd:

Typical usage will go to the desired directory:

$ goto
# $PWD = $HOME
$ goto me
# $PWD = ~/Dropbox/Programming/go/src/github.com/alexhenning
$ goto me/goto-cmd
# $PWD = ~/Dropbox/Programming/go/src//github.com/alexhenning/goto-cmd
$ goto github.com/alexhenning/goto-cmd
# $PWD = $GOPATH/github.com/alexhenning/goto-cmd
$ goto net/rpc
# $PWD = ~/.gvm/gos/go1.2.1/src/pkg/net/rpc

To get help:

Help can be gotten with -h, -help, or --help:

$ goto -help
# goto [-complete] dir
# 
# Goes to the given directory if possible otherwise. If "-complete" is
# present, instead of returning the directory to cd into, it returns a
# list of the possible completions.

To get completions:

The goto command can also be used to provide completions, this is used to provide tab completion. It’s as simple as:

$ goto -complete m
# me/
# mqp/
# mqp-src/
# math/
# mime/
Something went wrong with that request. Please try again.