2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Ghosttyで画面分割が面倒すぎたのでCLIツールを作った

2
Posted at

TL;DR

Ghosttyターミナルのペイン分割をコマンド一発で実行できるCLIツール ghostty-layout を作りました。

ghostty-layout demo

ghostty-layout 4   # 2x2の4分割
ghostty-layout 3x2 # 3列2行の6分割

きっかけ: tmux + Claude Code の相性問題

最近、ターミナルで Claude Code を使うことが増えました。ただ、tmux 上で Claude Code を動かすと Shift + Enter での改行が効かない という地味に辛い問題がありました。

これをきっかけに「そもそも tmux って本当に必要か?」と考え直してみたところ、自分が tmux で使っていた機能は主に 画面分割とペイン移動 だけだと気づきました。

tmux から Ghostty ネイティブへ

Ghostty にはビルトインのペイン分割機能があります。tmux のキーバインドを Ghostty の設定に移植したところ、tmux なしでも全く困らなくなりました。

# ~/.config/ghostty/config
keybind = ctrl+t>shift+backslash=new_split:right
keybind = ctrl+t>minus=new_split:down
keybind = ctrl+t>h=goto_split:left
keybind = ctrl+t>l=goto_split:right
keybind = ctrl+t>k=goto_split:up
keybind = ctrl+t>j=goto_split:down
keybind = ctrl+t>=equalize_splits

tmux を外したことで Claude Code の Shift + Enter 問題も解消し、ターミナルの起動も軽くなりました。

新たな課題: 手動分割が面倒

tmux を卒業して快適になった一方、新たな不満が出てきました。

毎回手動でペインを分割するのが面倒。

たとえば 4 分割したいとき、右に分割 → 左ペインに移動 → 下に分割 → 右ペインに移動 → 下に分割...と、キーバインドを何度も叩く必要があります。tmux なら tmux split-window を組み合わせてスクリプト化できましたが、Ghostty にはそういった CLI がありません。

「コマンド一発で好きなレイアウトを組めたら最高なのに」

そう思って作ったのが ghostty-layout です。

ghostty-layout の紹介

ghostty-layout demo

インストール

# ソースからビルド
git clone https://github.com/tackeyy/ghostty-layout.git
cd ghostty-layout
swift build -c release
sudo cp .build/release/ghostty-layout /usr/local/bin/

# または、リリースバイナリをダウンロード
curl -sL https://github.com/tackeyy/ghostty-layout/releases/latest/download/ghostty-layout \
  -o /usr/local/bin/ghostty-layout && chmod +x /usr/local/bin/ghostty-layout

基本的な使い方

プリセットレイアウトですぐに使えます。

コマンド レイアウト
ghostty-layout h 2列 横並び
ghostty-layout v 2行 縦並び
ghostty-layout 4 2x2 グリッド
ghostty-layout 6 2x3 グリッド
ghostty-layout 9 3x3 グリッド

カスタムグリッドも CxR 記法で自由に作れます。

ghostty-layout 3x2  # 3列2行
ghostty-layout 4x3  # 4列3行

最大 8x8 グリッドまで対応しています。

Ghostty の設定を自動検出

ghostty-layout は ~/.config/ghostty/config からキーバインド設定を自動で読み取ります。初回実行時に設定ファイルが自動生成されるので、手動設定は基本的に不要です。

# Ghosttyのキーバインドを変更した場合は同期
ghostty-layout --sync-config

# 同期しつつレイアウト適用も可能
ghostty-layout --sync-config 3x2

プレフィックスキー(例: ctrl+t > h)にも対応しています。

Raycast との連携

Raycast スクリプトコマンドとして登録すれば、ランチャーから一発でレイアウトを適用できます。

#!/bin/bash
# @raycast.schemaVersion 1
# @raycast.title Ghostty 4-split
# @raycast.mode silent

/usr/local/bin/ghostty-layout 4

仕組み

ghostty-layout は macOS の Accessibility API を使って、キーストロークをシミュレートすることで動作します。Ghostty のキーバインド設定を読み取り、分割 → 移動 → 分割... というキー操作を自動で実行します。

Swift で書いているのは、macOS の Accessibility API をネイティブに扱うためです。

初回実行時にアクセシビリティ権限の許可が必要です。
システム設定 > プライバシーとセキュリティ > アクセシビリティ から許可してください。

まとめ

Before After
tmux + Ghostty Ghostty のみ
Claude Code の Shift+Enter が効かない 問題なし
画面分割は手動で何ステップも必要 ghostty-layout 4 で一発

tmux → Ghostty ネイティブへの移行で Claude Code との相性問題を解消し、残った「手動分割の面倒さ」を ghostty-layout で解決しました。

Ghostty ユーザーで同じ悩みを持っている方がいたら、ぜひ試してみてください。

GitHub: https://github.com/tackeyy/ghostty-layout

スターを頂けると励みになります!

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?