tool-moyu.sh 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #!/bin/bash
  2. # =============================================================
  3. # tool-moyu.sh — AI「摸鱼」模拟器
  4. #
  5. # 作用:读取一段内容(默认本会话日志,或任意文件/stdin),
  6. # 循环「假装在处理」,模拟 AI 工作的样子。
  7. # 适合:需要看起来在干活、又不想真干活的时候 😏
  8. #
  9. # 用法:
  10. # ./tool-moyu.sh # 用内置内容摸鱼(默认)
  11. # ./tool-moyu.sh -n 3 # 循环 3 遍
  12. # ./tool-moyu.sh [文件] # 从文件读取(覆盖内置内容)
  13. # ./tool-moyu.sh --help # 帮助
  14. #
  15. # 选项:
  16. # -n N 循环 N 次(默认无限)
  17. # -d MS 每行间隔毫秒(默认随机 80-400)
  18. # -t 逐个字符「打字」效果
  19. # -s 静默模式:不打印假状态行,只循环内容
  20. # =============================================================
  21. set -euo pipefail
  22. LOOP_TIMES=0 # 0 = 无限
  23. DELAY_MS=0 # 0 = 随机 80-400
  24. TYPE_EFFECT=0
  25. SILENT=0
  26. show_usage() {
  27. sed -n '1,20p' "$0"
  28. exit 0
  29. }
  30. while [ $# -gt 0 ]; do
  31. case "$1" in
  32. -n) LOOP_TIMES="${2:?}"; shift 2 ;;
  33. -d) DELAY_MS="${2:?}"; shift 2 ;;
  34. -t) TYPE_EFFECT=1; shift ;;
  35. -s) SILENT=1; shift ;;
  36. --help|-h) show_usage ;;
  37. -*) echo "Unknown option: $1" >&2; exit 1 ;;
  38. *) break ;;
  39. esac
  40. done
  41. # 内置摸鱼内容(模拟一段 AI 工作汇报,可被文件参数覆盖)
  42. BUILTIN_CONTENT=$(cat <<'EOF'
  43. [13:00] Received request: set up CI/CD deployment pipeline
  44. [13:05] 🤖 Analyzing project structure, identifying Gogs repos and submodules
  45. [13:12] 🧠 Evaluating options: server resources tight, switch to local validation + SSH deploy
  46. [13:20] ✍️ Writing validate.sh / build.sh / deploy.sh scripts
  47. [13:35] ⚙️ Building deploy package locally, cross-compiling backend + frontend dist
  48. [13:48] 🔍 Fixing infinite restart caused by missing migrations directory
  49. [14:00] 📝 Writing aaPanel deployment guide, finalizing ports and domains
  50. [14:15] ✅ Local smoke test passed: MySQL 8.0 migration chain OK
  51. [14:30] 🚀 Deployed admin backend to test server, service active
  52. [14:40] 🌐 Frontend auto-deploy done, HTTP 200
  53. [14:50] 📊 Summarizing progress, updating backlog
  54. [15:00] 💬 Next: deploy backend-app, set up client/worker sites
  55. EOF
  56. )
  57. # 内容来源:文件参数 > 内置内容
  58. CONTENT="${1:-}"
  59. if [ -n "$CONTENT" ] && [ -f "$CONTENT" ]; then
  60. mapfile -t LINES < "$CONTENT"
  61. elif [ -n "$CONTENT" ] && [ "$CONTENT" != "-" ]; then
  62. echo "File not found: $CONTENT, falling back to built-in content." >&2
  63. mapfile -t LINES <<< "$BUILTIN_CONTENT"
  64. else
  65. mapfile -t LINES <<< "$BUILTIN_CONTENT"
  66. fi
  67. [ "${#LINES[@]}" -eq 0 ] && { echo "Content empty, nothing to slack on." >&2; exit 1; }
  68. # 随机延时
  69. rand_delay() {
  70. if [ "$DELAY_MS" -gt 0 ]; then sleep "$(awk -v d="$DELAY_MS" 'BEGIN{printf "%.3f", d/1000}')";
  71. else sleep "$(awk -v lo=80 -v hi=400 'BEGIN{srand(); printf "%.3f", (lo+int(rand()*(hi-lo+1)))/1000}')"; fi
  72. }
  73. # 假 AI 状态行(随机挑一个)
  74. STATUS=(
  75. "🤖 Analyzing session context..."
  76. "🧠 Thinking..."
  77. "📊 Summarizing key decisions..."
  78. "✍️ Generating execution summary..."
  79. "🔍 Searching knowledge graph..."
  80. "⚙️ Optimizing implementation..."
  81. "📝 Writing technical docs..."
  82. "✅ Checking code quality..."
  83. "🔄 Syncing progress report..."
  84. "💬 Generating next steps..."
  85. )
  86. run_once() {
  87. local idx=0 total="${#LINES[@]}"
  88. for line in "${LINES[@]}"; do
  89. idx=$((idx+1))
  90. [ "$SILENT" = "0" ] && [ $((RANDOM % 6)) -eq 0 ] && {
  91. printf "\r\033[K%s" "${STATUS[$((RANDOM % ${#STATUS[@]}))]}"
  92. rand_delay
  93. }
  94. if [ "$TYPE_EFFECT" = "1" ]; then
  95. local i
  96. for ((i=0; i<${#line}; i++)); do printf "%s" "${line:i:1}"; rand_delay; done
  97. echo ""
  98. else
  99. echo "$line"
  100. fi
  101. rand_delay
  102. done
  103. echo "" # 每遍之间空行
  104. }
  105. n=0
  106. while [ "$LOOP_TIMES" -eq 0 ] || [ "$n" -lt "$LOOP_TIMES" ]; do
  107. n=$((n+1))
  108. [ "$SILENT" = "0" ] && echo "—— Round $n of slacking ——"
  109. run_once
  110. done
  111. [ "$SILENT" = "0" ] && echo "🎣 Slacking done. Looks busy, actually did nothing."
  112. exit 0