| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- #!/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 动作、bash 命令与输出、工具调用返回(本会话就地取材)
- POOL=(
- # ---- AI 动作(少量图标) ----
- "🤖 analyzing dependency graph..."
- "📊 summarizing key decisions..."
- "✍️ drafting implementation plan..."
- "🔍 tracing call chain..."
- "🔒 reviewing security config..."
- "💬 preparing next steps..."
- # ---- bash 命令 ----
- "$ make tt a=/workspace/shell-kit"
- "$ go vet ./..."
- "$ go test ./..."
- "$ CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o admin_server ./cmd/server"
- "$ pnpm typecheck"
- "$ pnpm build"
- "$ rsync -az --delete release/frontend/ root@18.220.34.224:/www/wwwroot/household/"
- "$ ssh -p 10022 root@18.220.34.224 'systemctl restart backend-admin'"
- "$ mysql -h127.0.0.1 -uhousehold -p**** household -e 'SHOW TABLES;'"
- "$ curl -s -o /dev/null -w 'HTTP %{http_code}\\n' http://127.0.0.1:8081/"
- "$ journalctl -u backend-admin -n 30 --no-pager"
- "$ git log --oneline -5"
- "$ docker compose ps"
- "$ systemctl status backend-app"
- "$ cat internal/config/config.yaml"
- # ---- bash 输出 ----
- "ok git.ooo.ink/household/app 0.532s"
- "ok matrix/center 0.410s"
- "PASS"
- "✓ built in 26.39s"
- "✓ 307 modules transformed."
- "vite v7.3.6 building client environment for production..."
- "dist/assets/index-*.js 95.77 kB │ gzip: 37.38 kB"
- "[GIN-debug] Listening and serving HTTP on :8081"
- "migrations completed successfully"
- "systemd[1]: Started backend-admin.service - Household Backend Admin."
- "Active: active (running)"
- "HTTP 200"
- "mysql_native_password"
- "Tables_in_household: center_admins center_menus center_roles ..."
- "schema_migrations: 20260828001 | dirty=0"
- "ready for connections. Version: '8.0.46' socket: '/var/run/mysqld/mysqld.sock' port: 3306"
- # ---- 工具调用返回 ----
- "[read] docs/deploy-aaPanel.md 168 lines"
- "[search] "migrations" → 3 results"
- "[trace] RunMigrations → internal/pkg/database.RunMigrations"
- "[snippet] buildDSN → user:pass@tcp(host:port)/db?parseTime=True"
- "[build] release/backend/admin/admin_server (ELF, linux/amd64)"
- "[deploy] backend-admin → active"
- "[deploy] frontend-admin → HTTP 200"
- "[check] SSH root@18.220.34.224:10022 → ok"
- "[verify] curl admin.household.ooo.ink → 200 OK"
- "[skip] no changes, up to date"
- "[warn] config.yaml contains placeholder secret, leaving as-is on server"
- )
- # 随机生成一段“工作日志”(无时间戳,行数与内容每次不同)
- gen_random_content() {
- local count=$((9 + RANDOM % 10)) # 9-18 行
- LINES=()
- local i
- for ((i=0; i<count; i++)); do
- LINES+=("${POOL[$((RANDOM % ${#POOL[@]}))]}")
- done
- }
- # 内容来源:文件参数 > 随机生成
- 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..."
- "thinking..."
- "summarizing decisions..."
- "generating summary..."
- "searching graph..."
- "optimizing implementation..."
- "writing docs..."
- "checking code quality..."
- "syncing progress..."
- "preparing 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
|