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.
$ 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
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
The following examples show how to use the goto command, it’s pretty straightforward.
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
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.
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/