開発を~/projects に~/work に~/Desktop に
自分はgit clone して
ghq とは
ghq は、go get に
例えば、
ghq get https://github.com/junegunn/fzf
~/ghq/github.com/junegunn/fzf のように、
GitHub だけでなく
よく使うコマンド
# リポジトリを取得(clone)
ghq get https://github.com/junegunn/fzf
# SSH で取得(git@... 形式も使える)
ghq get git@github.com:msageha/portfolio.git
# 管理しているリポジトリの一覧
ghq list
# フルパスで一覧表示
ghq list --full-path
# 全リポジトリを一括更新
ghq list | ghq get --update --parallel
最後のgit pull する
ghq の設定
ghq の.gitconfig で
[ghq]
root = ~/Works/src
root をghq get で~/ghq に~/Works/src に
fzf と組み合わせる
ghq だけでもghq list の
fzf は
基本的なghq list のcd するだけです。
cd $(ghq list --full-path | fzf)
これだけでcd に
シェルごとの導入方法
インストール(共通)
まず
# Homebrew(macOS / Linux)
brew install ghq fzf
# mise でインストールする場合
mise use -g ghq@latest fzf@latest
# Go でインストールする場合(ghq のみ)
go install github.com/x-motemen/ghq@latest
.gitconfig に
git config --global ghq.root ~/Works/src
fish shell の場合
fish を
fisher install jethrokuan/fzf
fisher install decors/fish-ghq
decors/fish-ghq をCtrl+G を
fish は
zsh の場合
zsh では、.zshrc に
# .zshrc に追加
function ghq-fzf() {
local selected
selected=$(ghq list --full-path | fzf --preview "ls -la {}" --query "$LBUFFER")
if [ -n "$selected" ]; then
BUFFER="cd ${selected}"
zle accept-line
fi
zle clear-screen
}
zle -N ghq-fzf
bindkey '^g' ghq-fzf
これでCtrl+G を--preview オプションで
fzf 自体のCtrl+R で.zshrc に
# fzf のキーバインドと補完を有効化
source <(fzf --zsh)
bash の場合
bash でも.bashrc に
# .bashrc に追加
function ghq-fzf() {
local selected
selected=$(ghq list --full-path | fzf --preview "ls -la {}" --query "$READLINE_LINE")
if [ -n "$selected" ]; then
cd "$selected" || return
READLINE_LINE=""
READLINE_POINT=0
fi
}
bind -x '"\C-g": ghq-fzf'
Ctrl+G で
fzf の
# fzf のキーバインドと補完を有効化
eval "$(fzf --bash)"
実際の運用
自分のghq get するだけで、
また、ghq get を
#!/usr/bin/env bash
# リポジトリを一括取得するスクリプトの例
ghq get --shallow git@github.com:msageha/portfolio.git
ghq get --shallow git@github.com:your-org/project-a.git
ghq get --shallow git@github.com:your-org/project-b.git
# 取得済みリポジトリの一括更新
ghq list | ghq get --update --parallel
--shallow を
まとめ
- ghq: リポジトリを
URL ベースの ディレクトリ構造で 一元管理。 「どこに clone したっけ」 問題から 解放される - fzf との
組み合わせ : リポジトリ名をあいまい 検索して 一瞬で 移動。 リポジトリが 増える ほど 効果を 実感する - fish:
decors/fish-ghqプラグインを入れるだけ。 Ctrl+Gで即使える - zsh / bash: 関数を
設定ファイルに 追加して Ctrl+Gにバインド
リポジトリのcd でghq get で