Skip to content

Instantly share code, notes, and snippets.

@d-kuro
Last active January 24, 2021 07:02
Show Gist options
  • Save d-kuro/f4453b93ab5e9ff60be351d7d49b1476 to your computer and use it in GitHub Desktop.
Save d-kuro/f4453b93ab5e9ff60be351d7d49b1476 to your computer and use it in GitHub Desktop.
ghq と fzf で Git リポジトリと go get したやつをいい感じに管理する

ghq と fzf で Git リポジトリと go get したやつをいい感じに管理する

ghq とは

https://github.com/motemen/ghq

いい感じに git のリポジトリ管理するやつ 基本は git clone と置き換える感じで使う

インストール

$ go get github.com/motemen/ghq
$ cd $GOPATH/src/github.com/motemen/ghq
$ make install

これやっとけば go get した時点で使える気がする

export PATH=$PATH:$GOPATH/bin

root を複数指定する

ghq の管理ディレクトリはデフォルト ~/.ghq 配下。 これはそのままでよいが、go get したものは $GOPATH/src 配下に置かれるので両方のディレクトリからリポジトリの検索等を行えるようにする。

ghq のディレクトリ構成

https://github.com/motemen/ghq#directory-structures

~/.ghq
|-- code.google.com/
|   `-- p/
|       `-- vim/
`-- github.com/
    |-- google/
    |   `-- go-github/
    |-- motemen/
    |   `-- ghq/
    `-- urfave/
        `-- cli/

.gitconfig に追記する

[ghq]
  root = ~/.ghq
  root = ~/go/src
$ git config --global --get-all ghq.root                                                                                                                                                            127 ↵
~/.ghq
~/go/src

これで ghq list などのコマンドで go get したリポジトリも表示されるようになる。 ghq get したときはプライマリの ~/.ghq に配置される。

fzf 使う

fzf: 曖昧検索するやつ

https://github.com/junegunn/fzf

インストール

$ brew install fzf

使い方

$ ghq list | fzf

ディレクトリ移動

$ cd $(ghq list -p | fzf)
or
$ ghq look $(ghq list | fzf)

hub でターミナルからブラウザ開く

hub

https://github.com/github/hub

インストール

$ brew install hub

ブラウザで開く

$ hub browse
@d-kuro
Copy link
Author

d-kuro commented Jan 19, 2019

fish にしたらこうなった

$ ghq look (ghq list | fzf)

PATH の設定も変わったのでこっち参照
https://gist.github.com/d-kuro/d0c5cfce385f3959bc77102f04a5a8f1

@d-kuro
Copy link
Author

d-kuro commented Jun 23, 2019

$ cd (ghq list -p (ghq list | fzf))

ghq look は新しく fish が立ち上がるのでこっちのがいい

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment