#!/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 # 内置随机内容池(摸鱼动作短语,运行时会随机抽取拼成“工作日志”) POOL=( "🤖 Analyzing project structure..." "🧠 Evaluating deployment strategies..." "📊 Summarizing key decisions..." "✍️ Generating execution summary..." "🔍 Searching codebase knowledge graph..." "⚙️ Refactoring module boundary..." "📝 Drafting technical documentation..." "✅ Running unit tests..." "🔄 Syncing progress report..." "💬 Preparing next action items..." "🚀 Building release package..." "🌐 Deploying frontend static assets..." "🗄️ Migrating database schema..." "🔐 Validating security configuration..." "🧪 Executing smoke test..." "📈 Analyzing performance bottlenecks..." "🧩 Resolving dependency conflicts..." "🛠️ Fixing cross-compilation issue..." "📦 Packaging dist artifacts..." "🖥️ Restarting backend service..." "🔁 Iterating on review feedback..." "📚 Updating API documentation..." "🎯 Optimizing query performance..." "🧹 Cleaning up dead code..." "🔒 Hardening authentication flow..." "🌍 Localizing UI strings..." "⚡ Caching hot-path responses..." "📋 Verifying requirements coverage..." "🏗️ Scaffolding new module..." "🔔 Sending build notification..." ) # 随机生成一段“工作日志”(无时间戳,行数与内容每次不同) gen_random_content() { local count=$((6 + RANDOM % 8)) # 6-13 行 LINES=() local i for ((i=0; i 随机生成 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 random content." >&2 gen_random_content else gen_random_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)) run_once done exit 0