0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Macでgit のローカルリポジトリまで一気に移動+vscodeで開く(ghq + fzf)

Last updated at Posted at 2024-12-07

ghq と fzf を使ったリポジトリ管理の効率化

この記事では、ghqfzf を使って、Git の作業フォルダを簡単に管理・移動する方法をご紹介します。特に、複数のリポジトリを扱う場合に非常に便利です。

前提

  • fzf: あいまい検索機能を提供するツール(要インストール)
  • ghq: Git リポジトリの管理ツール(要インストール)

手順

1. ghqfzf をインストール

まず、ghqfzf を Homebrew でインストールします。

brew install ghq fzf

2.git の作業フォルダを登録

下記コマンドで~/.gitconfigに追記されます。

git config --global ghq.root /Users/HOGE/src

3.zshrc か bashrc に以下を追記

cdrepo() {
  local repodir=$(ghq list | fzf -1 +m) &&
  echo 以下のディレクトリに移動します : $(ghq root)/$repodir
  if [ -n "$repodir" ]; then
   cd $(ghq root)/$repodir
  fi
}
vsrepo() {
  local repodir=$(ghq list | fzf -1 +m) &&
  echo vscodeで以下を開きます : $(ghq root)/$repodir
  if [ -n "$repodir" ]; then
   code $(ghq root)/$repodir
  fi
}

4.上記設定を即時反映

どちらかで(3.で書き換えた方のファイルを指定すれば)OK

source ~/.zshrc
source ~/.bashrc

おまけ

  • fzf は指定した結果を標準出力してくれるのが便利。他のコマンドに結果を渡せるので、他の目的にも使える。

以上

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?