31 lines
925 B
Bash
Executable File
31 lines
925 B
Bash
Executable File
#!/bin/bash
|
|
# Usage: setcmd.sh 'cmd1' 'cmd2' ...
|
|
python3 - "$@" << 'EOF'
|
|
import sys, json, re
|
|
|
|
from datetime import datetime
|
|
# sys.argv strings are already properly decoded by Python — json.dumps handles all escaping
|
|
commands = sys.argv[1:]
|
|
ts = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
|
js = "var _ts = \"" + ts + "\";\nvar _cmds = " + json.dumps(commands, indent=2) + ";"
|
|
|
|
import os
|
|
target = os.path.expanduser('~/.openclaw/workspace/cmd.html')
|
|
tmpl = os.path.join(os.path.dirname(os.path.abspath(sys.argv[0])), 'cmd.html')
|
|
if not os.path.exists(target):
|
|
import shutil; shutil.copy(tmpl, target)
|
|
|
|
with open(target, 'r') as f:
|
|
html = f.read()
|
|
|
|
html = re.sub(
|
|
r'/\* COMMANDS_START \*/.*?/\* COMMANDS_END \*/',
|
|
'/* COMMANDS_START */\n' + js + '\n/* COMMANDS_END */',
|
|
html, flags=re.DOTALL
|
|
)
|
|
|
|
with open(target, 'w') as f:
|
|
f.write(html)
|
|
print(f'cmd.html updated ({len(commands)} command(s))')
|
|
EOF
|