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?

【zed】LazyGitを今開いているrepoで表示したい(ネストしたrepoでも)

0
Last updated at Posted at 2026-04-12

TL;DR

tasksのcommandにこれを使え!

tasks.json
"command": "$root = (git -C (Split-Path \"$ZED_FILE\") rev-parse --show-toplevel 2>$null); lazygit -p ($root ?? \"$ZED_WORKTREE_ROOT\")",

経緯

こんにちは。
sledgeというペイントソフトを作っているものです。
zed、触った瞬間その速さに惚れて移行を決意しました。

自分はモロにVSCode+GitGraphから移行なので、こういった記事を読んでLazyGitを導入しました。
設定も上記記事をコピペ。

tasks.json
[
  {
    "label": "LazyGit",
    "command": "lazygit -p $ZED_WORKTREE_ROOT",
    "shell": { "program": "pwsh" },
    "hide": "on_success",
    "reveal_target": "center",
    "show_summary": false,
    "show_command": false,
    "allow_concurrent_runs": true,
    "use_new_terminal": true
  }
]
keymap.json
[
  {
    "context": "Workspace",
    "bindings": {
      "ctrl-shift-g": [
        "task::Spawn",
        { "task_name": "LazyGit" }
      ]
    }
  }
]

直面した問題

しかしながら、自分のプロジェクトは以下のような構成になっています。

★=gitリポジトリ

★ sledge-pdm :PDMリポジトリ
┣ apps :関連アプリやサイト
┃ ┣ ★ sledge
┃ ┣ ★ sledge-website
┃ ┗ ...
┗ packages :共通パッケージなど
  ┣ ★ core
  ┣ ★ ui
  ┗ ...

sledge-pdmリポジトリの下にまたリポジトリがネストしている形になっています。
アプリ側からパッケージ側のコードを見たり修正したり、またその逆もあるので基本的にはsledge-pdmを開いておくわけですが、

image.png

例えばpackages/uiの中のファイルを開いたままLazyGitのショートカット(Ctrl+Shift+G)を押すと、

image.png

packages/uiを開いていてほしいところが、sledge-pdmを開いてしまいます。
これは設定で

tasks.json
"command": "lazygit -p $ZED_WORKTREE_ROOT"

と、$ZED_WORKTREE_ROOTを参照して開いているためで、公式Docsではこれは

- `ZED_WORKTREE_ROOT`: absolute path to the root of the current worktree. (e.g. `/Users/my-user/path/to/project`)

ワークツリーのrootを参照する、と書いてあります。sledge-pdmが開かれて当然ですね。

なんとかする

ZED_CURRENT_REPOSITORYみたいな変数があればよかったのですが当然そんなものはなく、Claude Codeにお願いしてみたところ、以下の設定を書いてくれました。

tasks.json
[
  {
    "label": "LazyGit",
    "command": "$root = (git -C (Split-Path \"$ZED_FILE\") rev-parse --show-toplevel 2>$null); lazygit -p ($root ?? \"$ZED_WORKTREE_ROOT\")",
    "shell": { "program": "pwsh" },
    "hide": "on_success",
    "reveal_target": "center",
    "show_summary": false,
    "show_command": false,
    "allow_concurrent_runs": true,
    "use_new_terminal": true,
  },
]

保存して再度ショートカットでLazyGitを起動すると、開いている直近のリポジトリ(ui)でしっかり起動してくれました。

image.png

何が変わったのか

修正の肝はここでした。

$root = (git -C (Split-Path \"$ZED_FILE\") rev-parse --show-toplevel 2>$null); lazygit -p ($root ?? \"$ZED_WORKTREE_ROOT\")

git rev-parse --show-toplevel入力したファイルが所属するリポジトリのパスを表示してくれるという今回の目的にドンピシャなコマンドだったようで、これをlazygitのパスに渡すことで解決できたみたいです。

おわり

zed+LazyGit思ったよりいいぞ、と思った直後に起きた問題だったので、無事解決できてよかったです。

image.png

sledge、よかったら触ってみてね

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?