tool-moyu.sh 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. # 内置随机内容池(摸鱼动作短语,运行时会随机抽取拼成“工作日志”)
  42. POOL=(
  43. "🤖 Analyzing project structure..."
  44. "🧠 Evaluating deployment strategies..."
  45. "📊 Summarizing key decisions..."
  46. "✍️ Generating execution summary..."
  47. "🔍 Searching codebase knowledge graph..."
  48. "⚙️ Refactoring module boundary..."
  49. "📝 Drafting technical documentation..."
  50. "✅ Running unit tests..."
  51. "🔄 Syncing progress report..."
  52. "💬 Preparing next action items..."
  53. "🚀 Building release package..."
  54. "🌐 Deploying frontend static assets..."
  55. "🗄️ Migrating database schema..."
  56. "🔐 Validating security configuration..."
  57. "🧪 Executing smoke test..."
  58. "📈 Analyzing performance bottlenecks..."
  59. "🧩 Resolving dependency conflicts..."
  60. "🛠️ Fixing cross-compilation issue..."
  61. "📦 Packaging dist artifacts..."
  62. "🖥️ Restarting backend service..."
  63. "🔁 Iterating on review feedback..."
  64. "📚 Updating API documentation..."
  65. "🎯 Optimizing query performance..."
  66. "🧹 Cleaning up dead code..."
  67. "🔒 Hardening authentication flow..."
  68. "🌍 Localizing UI strings..."
  69. "⚡ Caching hot-path responses..."
  70. "📋 Verifying requirements coverage..."
  71. "🏗️ Scaffolding new module..."
  72. "🔔 Sending build notification..."
  73. )
  74. # 随机生成一段“工作日志”(无时间戳,行数与内容每次不同)
  75. gen_random_content() {
  76. local count=$((6 + RANDOM % 8)) # 6-13 行
  77. LINES=()
  78. local i
  79. for ((i=0; i<count; i++)); do
  80. LINES+=("${POOL[$((RANDOM % ${#POOL[@]}))]}")
  81. done
  82. }
  83. # 内容来源:文件参数 > 随机生成
  84. CONTENT="${1:-}"
  85. if [ -n "$CONTENT" ] && [ -f "$CONTENT" ]; then
  86. mapfile -t LINES < "$CONTENT"
  87. elif [ -n "$CONTENT" ] && [ "$CONTENT" != "-" ]; then
  88. echo "File not found: $CONTENT, falling back to random content." >&2
  89. gen_random_content
  90. else
  91. gen_random_content
  92. fi
  93. [ "${#LINES[@]}" -eq 0 ] && { echo "Content empty, nothing to slack on." >&2; exit 1; }
  94. # 随机延时
  95. rand_delay() {
  96. if [ "$DELAY_MS" -gt 0 ]; then sleep "$(awk -v d="$DELAY_MS" 'BEGIN{printf "%.3f", d/1000}')";
  97. else sleep "$(awk -v lo=80 -v hi=400 'BEGIN{srand(); printf "%.3f", (lo+int(rand()*(hi-lo+1)))/1000}')"; fi
  98. }
  99. # 假 AI 状态行(随机挑一个)
  100. STATUS=(
  101. "🤖 Analyzing session context..."
  102. "🧠 Thinking..."
  103. "📊 Summarizing key decisions..."
  104. "✍️ Generating execution summary..."
  105. "🔍 Searching knowledge graph..."
  106. "⚙️ Optimizing implementation..."
  107. "📝 Writing technical docs..."
  108. "✅ Checking code quality..."
  109. "🔄 Syncing progress report..."
  110. "💬 Generating next steps..."
  111. )
  112. run_once() {
  113. local idx=0 total="${#LINES[@]}"
  114. for line in "${LINES[@]}"; do
  115. idx=$((idx+1))
  116. [ "$SILENT" = "0" ] && [ $((RANDOM % 6)) -eq 0 ] && {
  117. printf "\r\033[K%s" "${STATUS[$((RANDOM % ${#STATUS[@]}))]}"
  118. rand_delay
  119. }
  120. if [ "$TYPE_EFFECT" = "1" ]; then
  121. local i
  122. for ((i=0; i<${#line}; i++)); do printf "%s" "${line:i:1}"; rand_delay; done
  123. echo ""
  124. else
  125. echo "$line"
  126. fi
  127. rand_delay
  128. done
  129. echo "" # 每遍之间空行
  130. }
  131. n=0
  132. while [ "$LOOP_TIMES" -eq 0 ] || [ "$n" -lt "$LOOP_TIMES" ]; do
  133. n=$((n+1))
  134. [ "$SILENT" = "0" ] && echo "—— Round $n of slacking ——"
  135. run_once
  136. done
  137. [ "$SILENT" = "0" ] && echo "🎣 Slacking done. Looks busy, actually did nothing."
  138. exit 0