#!/bin/bash # ============================================================= # tool-moyu.sh — AI「摸鱼」模拟器 # # 作用:读取一段内容(默认本会话日志,或任意文件/stdin), # 循环「假装在处理」,模拟 AI 工作的样子。 # 适合:需要看起来在干活、又不想真干活的时候 😏 # # 用法: # ./tool-moyu.sh # 用内置内容摸鱼(默认) # ./tool-moyu.sh -n 3 # 循环 3 遍 # ./tool-moyu.sh [文件] # 从文件读取(覆盖内置内容) # ./tool-moyu.sh --help # 帮助 # # 选项: # -n N 循环 N 次(默认无限) # -d MS 每行间隔毫秒(默认随机 80-400) # -t 逐个字符「打字」效果 # -s 静默模式:不打印假状态行,只循环内容 # ============================================================= set -euo pipefail LOOP_TIMES=0 # 0 = 无限 DELAY_MS=0 # 0 = 随机 80-400 TYPE_EFFECT=0 SILENT=0 show_usage() { sed -n '1,20p' "$0" exit 0 } while [ $# -gt 0 ]; do case "$1" in -n) LOOP_TIMES="${2:?}"; shift 2 ;; -d) DELAY_MS="${2:?}"; shift 2 ;; -t) TYPE_EFFECT=1; shift ;; -s) SILENT=1; shift ;; --help|-h) show_usage ;; -*) echo "Unknown option: $1" >&2; exit 1 ;; *) break ;; esac done # 内置摸鱼内容(模拟一段 AI 工作汇报,可被文件参数覆盖) BUILTIN_CONTENT=$(cat <<'EOF' [13:00] Received request: set up CI/CD deployment pipeline [13:05] 🤖 Analyzing project structure, identifying Gogs repos and submodules [13:12] 🧠 Evaluating options: server resources tight, switch to local validation + SSH deploy [13:20] ✍️ Writing validate.sh / build.sh / deploy.sh scripts [13:35] ⚙️ Building deploy package locally, cross-compiling backend + frontend dist [13:48] 🔍 Fixing infinite restart caused by missing migrations directory [14:00] 📝 Writing aaPanel deployment guide, finalizing ports and domains [14:15] ✅ Local smoke test passed: MySQL 8.0 migration chain OK [14:30] 🚀 Deployed admin backend to test server, service active [14:40] 🌐 Frontend auto-deploy done, HTTP 200 [14:50] 📊 Summarizing progress, updating backlog [15:00] 💬 Next: deploy backend-app, set up client/worker sites EOF ) # 内容来源:文件参数 > 内置内容 CONTENT="${1:-}" if [ -n "$CONTENT" ] && [ -f "$CONTENT" ]; then mapfile -t LINES < "$CONTENT" elif [ -n "$CONTENT" ] && [ "$CONTENT" != "-" ]; then echo "File not found: $CONTENT, falling back to built-in content." >&2 mapfile -t LINES <<< "$BUILTIN_CONTENT" else mapfile -t LINES <<< "$BUILTIN_CONTENT" fi [ "${#LINES[@]}" -eq 0 ] && { echo "Content empty, nothing to slack on." >&2; exit 1; } # 随机延时 rand_delay() { if [ "$DELAY_MS" -gt 0 ]; then sleep "$(awk -v d="$DELAY_MS" 'BEGIN{printf "%.3f", d/1000}')"; else sleep "$(awk -v lo=80 -v hi=400 'BEGIN{srand(); printf "%.3f", (lo+int(rand()*(hi-lo+1)))/1000}')"; fi } # 假 AI 状态行(随机挑一个) STATUS=( "🤖 Analyzing session context..." "🧠 Thinking..." "📊 Summarizing key decisions..." "✍️ Generating execution summary..." "🔍 Searching knowledge graph..." "⚙️ Optimizing implementation..." "📝 Writing technical docs..." "✅ Checking code quality..." "🔄 Syncing progress report..." "💬 Generating next steps..." ) run_once() { local idx=0 total="${#LINES[@]}" for line in "${LINES[@]}"; do idx=$((idx+1)) [ "$SILENT" = "0" ] && [ $((RANDOM % 6)) -eq 0 ] && { printf "\r\033[K%s" "${STATUS[$((RANDOM % ${#STATUS[@]}))]}" rand_delay } if [ "$TYPE_EFFECT" = "1" ]; then local i for ((i=0; i<${#line}; i++)); do printf "%s" "${line:i:1}"; rand_delay; done echo "" else echo "$line" fi rand_delay done echo "" # 每遍之间空行 } n=0 while [ "$LOOP_TIMES" -eq 0 ] || [ "$n" -lt "$LOOP_TIMES" ]; do n=$((n+1)) [ "$SILENT" = "0" ] && echo "—— Round $n of slacking ——" run_once done [ "$SILENT" = "0" ] && echo "🎣 Slacking done. Looks busy, actually did nothing." exit 0