This commit is contained in:
2025-07-05 13:48:50 +09:00
parent 00c9af330b
commit 9758126225
26 changed files with 3134 additions and 0 deletions

304
setup-advanced.sh Executable file
View File

@ -0,0 +1,304 @@
#!/bin/bash
# Claude Code Advanced Setup Script
# ターミナル環境との統合、AI連携、MCP設定を一括で行う
set -e
# カラー定義
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
# 設定
CLAUDE_DIR="$HOME/git/claude"
BACKUP_DIR="$HOME/.claude-backup-$(date +%Y%m%d-%H%M%S)"
echo -e "${BLUE}🤖 Claude Code Advanced Setup${NC}"
echo -e "${BLUE}===============================${NC}"
# バックアップ作成
create_backup() {
echo -e "${GREEN}既存設定のバックアップを作成中...${NC}"
mkdir -p "$BACKUP_DIR"
# 既存の設定をバックアップ
[[ -f ~/.zshrc ]] && cp ~/.zshrc "$BACKUP_DIR/"
[[ -f ~/.claude/settings.json ]] && cp ~/.claude/settings.json "$BACKUP_DIR/"
[[ -f ~/.claude/claude_desktop_config.json ]] && cp ~/.claude/claude_desktop_config.json "$BACKUP_DIR/"
[[ -f ~/.tmux.conf ]] && cp ~/.tmux.conf "$BACKUP_DIR/"
echo -e "${GREEN}✓ バックアップ完了: $BACKUP_DIR${NC}"
}
# 依存関係のインストール
install_dependencies() {
echo -e "${GREEN}依存関係をインストール中...${NC}"
# OS検出
if [[ "$(uname)" == "Darwin" ]]; then
# macOS
if ! command -v brew &> /dev/null; then
echo -e "${RED}Homebrewがインストールされていません${NC}"
echo "https://brew.sh/ からインストールしてください"
exit 1
fi
brew install ripgrep fd bat exa tmux git nodejs npm
elif [[ "$(uname)" == "Linux" ]]; then
# Linux (Arch Linux想定)
if command -v pacman &> /dev/null; then
sudo pacman -S --noconfirm ripgrep fd bat exa tmux git nodejs npm
elif command -v apt &> /dev/null; then
sudo apt update
sudo apt install -y ripgrep fd-find bat exa tmux git nodejs npm
fi
fi
echo -e "${GREEN}✓ 依存関係のインストール完了${NC}"
}
# zsh設定
setup_zsh() {
echo -e "${GREEN}zsh設定を構成中...${NC}"
# .zshrcに追加
if ! grep -q "source.*zshrc_claude" ~/.zshrc 2>/dev/null; then
echo "" >> ~/.zshrc
echo "# Claude Code Enhanced Configuration" >> ~/.zshrc
echo "source $CLAUDE_DIR/shell-config/.zshrc_claude" >> ~/.zshrc
echo -e "${GREEN}✓ .zshrcに設定を追加しました${NC}"
else
echo -e "${YELLOW}既に.zshrcに設定があります${NC}"
fi
}
# tmux設定
setup_tmux() {
echo -e "${GREEN}tmux設定を構成中...${NC}"
if [[ ! -f ~/.tmux.conf ]]; then
cat > ~/.tmux.conf << 'EOF'
# Claude Code tmux configuration
# プレフィックスキーの変更
set -g prefix C-a
unbind C-b
bind C-a send-prefix
# ペインの分割
bind | split-window -h
bind - split-window -v
# ペインの移動
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
# Claude Code専用のキーバインド
bind C command-prompt -p "claude prompt:" "new-window 'claude \"%%\"'"
bind c-r new-window "claude --resume"
# ステータスラインの設定
set -g status-left '[#S] '
set -g status-right '%Y-%m-%d %H:%M'
set -g window-status-current-style 'bg=green,fg=black'
# マウスサポート
set -g mouse on
# 256色対応
set -g default-terminal "screen-256color"
EOF
echo -e "${GREEN}✓ tmux設定ファイルを作成しました${NC}"
else
echo -e "${YELLOW}既存のtmux設定があります${NC}"
fi
}
# MCP設定
setup_mcp() {
echo -e "${GREEN}MCP設定を構成中...${NC}"
# MCPセットアップスクリプトを実行
chmod +x "$CLAUDE_DIR/mcp/setup-mcp.sh"
bash "$CLAUDE_DIR/mcp/setup-mcp.sh" all
echo -e "${GREEN}✓ MCP設定完了${NC}"
}
# AI統合設定
setup_ai_integration() {
echo -e "${GREEN}AI統合機能を設定中...${NC}"
# スクリプトに実行権限を付与
chmod +x "$CLAUDE_DIR/scripts/ai-integration.sh"
# 必要なディレクトリを作成
mkdir -p "$HOME/claude-logs"
mkdir -p "$HOME/chatgpt-logs"
mkdir -p "$HOME/.ai-context"
echo -e "${GREEN}✓ AI統合機能の設定完了${NC}"
}
# Claude Code設定
setup_claude_settings() {
echo -e "${GREEN}Claude Code設定を構成中...${NC}"
mkdir -p ~/.claude
# settings.jsonの作成
cat > ~/.claude/settings.json << 'EOF'
{
"editor": "vim",
"theme": "dark",
"hooks": {
"before_bash": "~/git/claude/scripts/safe-command-check.sh"
},
"thinking": {
"enabled": true,
"depth": "normal"
}
}
EOF
echo -e "${GREEN}✓ Claude Code設定ファイルを作成しました${NC}"
}
# Vim統合設定
setup_vim() {
echo -e "${GREEN}Vim統合設定を構成中...${NC}"
# .vimrcに追加
if [[ -f ~/.vimrc ]]; then
if ! grep -q "Claude Code" ~/.vimrc; then
cat >> ~/.vimrc << 'EOF'
" Claude Code integration
nnoremap <leader>cc :!claude "このコードをレビューして: %"<CR>
nnoremap <leader>ce :!claude "このエラーを解決して: %"<CR>
nnoremap <leader>ct :!claude "このファイルのテストを作成して: %"<CR>
vnoremap <leader>cs :w !claude "この部分を説明して"<CR>
EOF
echo -e "${GREEN}✓ Vim設定を追加しました${NC}"
else
echo -e "${YELLOW}既にVim設定があります${NC}"
fi
fi
}
# 権限設定
setup_permissions() {
echo -e "${GREEN}実行権限を設定中...${NC}"
# すべてのスクリプトに実行権限を付与
find "$CLAUDE_DIR/scripts" -name "*.sh" -exec chmod +x {} \;
find "$CLAUDE_DIR/mcp" -name "*.sh" -exec chmod +x {} \;
chmod +x "$CLAUDE_DIR/setup-advanced.sh"
echo -e "${GREEN}✓ 権限設定完了${NC}"
}
# テスト実行
run_tests() {
echo -e "${GREEN}設定をテスト中...${NC}"
# 基本的な動作確認
echo "zsh設定テスト..."
if source "$CLAUDE_DIR/shell-config/.zshrc_claude"; then
echo -e "${GREEN}✓ zsh設定OK${NC}"
else
echo -e "${RED}✗ zsh設定エラー${NC}"
fi
echo -e "${GREEN}✓ テスト完了${NC}"
}
# 使用方法の表示
show_usage() {
echo -e "${BLUE}使用方法:${NC}"
echo " $0 all - 全ての設定を実行"
echo " $0 deps - 依存関係のインストール"
echo " $0 zsh - zsh設定"
echo " $0 tmux - tmux設定"
echo " $0 mcp - MCP設定"
echo " $0 ai - AI統合設定"
echo " $0 claude - Claude Code設定"
echo " $0 vim - Vim統合設定"
echo " $0 test - 設定テスト"
echo " $0 help - このヘルプ"
echo ""
echo -e "${YELLOW}推奨: $0 all で全設定を実行${NC}"
}
# 完了メッセージ
show_completion() {
echo -e "${GREEN}🎉 Claude Code Advanced Setup完了${NC}"
echo ""
echo -e "${BLUE}次の手順:${NC}"
echo "1. ターミナルを再起動するか 'source ~/.zshrc' を実行"
echo "2. 'claude-env' コマンドで環境をテスト"
echo "3. 'ai-tmux' でClaude Code作業環境を起動"
echo "4. '/user:help' でカスタムヘルプを確認"
echo ""
echo -e "${YELLOW}利用可能な新機能:${NC}"
echo "- claude-analyze <file> - ファイル解析"
echo "- claude-review <file> - コードレビュー"
echo "- claude-test <file> - テスト生成"
echo "- ai-compare <task> - 複数AI比較"
echo "- ai-import <log> - ChatGPT会話インポート"
echo "- mcp-setup - MCP設定"
echo ""
echo -e "${GREEN}Happy coding with Claude Code! 🚀${NC}"
}
# メイン処理
case "$1" in
all)
create_backup
install_dependencies
setup_zsh
setup_tmux
setup_mcp
setup_ai_integration
setup_claude_settings
setup_vim
setup_permissions
run_tests
show_completion
;;
deps)
install_dependencies
;;
zsh)
setup_zsh
;;
tmux)
setup_tmux
;;
mcp)
setup_mcp
;;
ai)
setup_ai_integration
;;
claude)
setup_claude_settings
;;
vim)
setup_vim
;;
test)
run_tests
;;
help|--help|-h)
show_usage
;;
*)
show_usage
exit 1
;;
esac