Skip to content

Instantly share code, notes, and snippets.

@taiyoh
Created February 12, 2026 23:44
Show Gist options
  • Select an option

  • Save taiyoh/43538a8667a7835fefef7fd426147e0c to your computer and use it in GitHub Desktop.

Select an option

Save taiyoh/43538a8667a7835fefef7fd426147e0c to your computer and use it in GitHub Desktop.
my tmux settup script
#!/usr/bin/env bash
set -euo pipefail
# Usage:
# scripts/tmux_llm_layout.sh
# scripts/tmux_llm_layout.sh --llm codex
# scripts/tmux_llm_layout.sh --new-session [session_name]
# scripts/tmux_llm_layout.sh --new-session [session_name] --llm codex
#
# Env overrides:
# LLM_CMD=codex scripts/tmux_llm_layout.sh
# FILES_CMD='yazi .' LLM_CMD='claude' GIT_CMD='lazygit' scripts/tmux_llm_layout.sh
SESSION_NAME="dev"
FILES_CMD="${FILES_CMD:-yazi .}"
LLM_CMD="${LLM_CMD:-claude}"
GIT_CMD="${GIT_CMD:-lazygit}"
NEW_SESSION=false
while [[ $# -gt 0 ]]; do
case "$1" in
--new-session)
NEW_SESSION=true
if [[ -n "${2:-}" && "${2:0:1}" != "-" ]]; then
SESSION_NAME="$2"
shift
fi
;;
--llm)
if [[ -z "${2:-}" || "${2:0:1}" == "-" ]]; then
echo "エラー: --llm にはコマンド名を指定してください。"
exit 1
fi
LLM_CMD="$2"
shift
;;
*)
echo "不明な引数: $1"
echo "Usage: scripts/tmux_llm_layout.sh [--new-session [session_name]] [--llm <command>]"
exit 1
;;
esac
shift
done
setup_layout() {
local target_window="$1"
local files_pane
local llm_pane
local git_pane
# Use pane IDs instead of numeric indexes to work with any pane-base-index.
files_pane="$(tmux display-message -p -t "$target_window" '#{pane_id}')"
llm_pane="$(tmux split-window -h -P -F '#{pane_id}' -t "$files_pane")"
git_pane="$(tmux split-window -v -P -F '#{pane_id}' -t "$llm_pane")"
# Resize according to requested values
tmux resize-pane -t "$llm_pane" -D 5
tmux resize-pane -t "$files_pane" -R 10
# Add pane labels
tmux set-option -t "$target_window" pane-border-status top
tmux set-option -t "$target_window" pane-border-format ' #{pane_title} '
tmux select-pane -t "$files_pane" -T files
tmux select-pane -t "$llm_pane" -T llm
tmux select-pane -t "$git_pane" -T git
# Launch tools
tmux send-keys -t "$files_pane" "$FILES_CMD" C-m
tmux send-keys -t "$llm_pane" "$LLM_CMD" C-m
tmux send-keys -t "$git_pane" "$GIT_CMD" C-m
}
if [[ "$NEW_SESSION" == "true" ]]; then
if ! tmux has-session -t "$SESSION_NAME" 2>/dev/null; then
new_window=""
tmux -2 new-session -d -s "$SESSION_NAME"
new_window="$(tmux display-message -p -t "${SESSION_NAME}:" '#S:#I')"
setup_layout "$new_window"
fi
if [[ -t 1 ]]; then
tmux attach -t "$SESSION_NAME"
else
echo "session '${SESSION_NAME}' を作成/再利用しました(非TTYのためattachはスキップ)。"
fi
exit 0
fi
if [[ -z "${TMUX:-}" ]]; then
echo "tmux内で実行してください。"
echo "新規起動込みで行う場合: scripts/tmux_llm_layout.sh --new-session [session_name]"
exit 1
fi
CURRENT_WINDOW="$(tmux display-message -p '#S:#I')"
setup_layout "$CURRENT_WINDOW"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment