LoginSignup
2
2

More than 5 years have passed since last update.

gogo: A fish-shell function to jump to go project dir

Last updated at Posted at 2017-02-03

最近golangを使っているうちになかなか良い言語だなあと思い始めてきた感じがしますが、GOPATH以下のディレクトリ階層の深さがJavaか大江戸線かというぐらいにひどくて辟易しております。面倒なので以下のようなfish-shell関数を使ってjumpできるようにしました。

~/.config/fish/functions/gogo.fish

function gogo
  test (count $argv) -ge 1; and set TO $argv[1]
  test (count $argv) -ge 2; and set IDX $argv[2]

  if test -z "$TO"
    echo "target is required" >&2
    return 1
  end

  set L (find $GOPATH -type d | grep -v vendor | grep "$TO\$\|/$TO""[^/]*\$")
  set N (count $L)
  switch $N
  case '0'
    echo "Not found" >&2
    return 1
  case '1'
    cd $L
  case '*'
    if test -n "$IDX"
      cd $L[$IDX]
    else
      for I in (seq (count $L))
        echo "$I: $L[$I]"
      end
    end
  end
end

USAGE:

x> gogo grafana/grafana

x> gogo grafana
1: /GO/PATH/src/github.com/grafana
2: /GO/PATH/src/github.com/grafana/grafana
3: ... (snip) ...
x> gogo grafana 2
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2