Files
notebook/script/refactor_strudel.sh
HarakaraSite 0be0a702c9 3rd commit
2026-02-11 21:26:03 +09:00

52 lines
1.8 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# スクリプトの場所 (scripts/) からプロジェクトルート (notebook/) を動的に取得
BASE_DIR=$(cd "$(dirname "$0")/.." && pwd)
REFACTOR_DIR="$BASE_DIR/refactoring"
SKILL_FILE="$BASE_DIR/.gemini/skills/strudel_refactor.md"
# 出力先フォルダの作成
mkdir -p "$REFACTOR_DIR"
# 引数がある場合はそれを使用し、ない場合は strudel/ フォルダの全mdファイルを対象にする
if [ $# -gt 0 ]; then
files=("$@")
else
files=("$BASE_DIR/strudel"/*.md)
fi
echo "Strudel Code Analysis & Refactoring Skill started..."
for file in "${files[@]}"; do
# 除外設定
[[ "$file" == *"Strudel Making Sound.md"* ]] && continue
[[ "$file" == *"Strudel Study.md"* ]] && continue
[[ "$file" == *"/refactoring/"* ]] && continue
[[ "$file" == *"/scripts/"* ]] && continue
[ -f "$file" ] || continue
filename=$(basename "$file")
echo "Processing $filename..."
# スキルファイルをシステムプロンプトとして使用
tmp_file="$REFACTOR_DIR/tmp_$filename"
cat "$file" | gemini-cli --system "$(cat "$SKILL_FILE")" > "$tmp_file"
if [ $? -eq 0 ]; then
# 1行目から提案されたファイル名を抽出
suggested_name=$(head -n 1 "$tmp_file" | grep "FILENAME:" | sed 's/FILENAME: //g' | tr -d '\r')
if [ -n "$suggested_name" ]; then
# 1行目FILENAME行を除去してリネーム保存
tail -n +2 "$tmp_file" > "$REFACTOR_DIR/$suggested_name"
rm "$tmp_file"
echo "Successfully refactored and renamed to: $suggested_name"
else
mv "$tmp_file" "$REFACTOR_DIR/$filename"
echo "Successfully refactored: $filename (Rename tag not found)"
fi
else
rm -f "$tmp_file"
echo "Error processing $filename"
fi
done