Files
usaco/usaco
T
2026-09-24 13:12:37 +01:00

76 lines
3.9 KiB
Bash
Executable File

#!/usr/bin/env bash
# usaco - manage USACO problems
# Usage:
# usaco i Interactive mode: holds a current problem so commands
# drop the name (aliases: interactive, repl)
# s <name> select a problem (bare name works too)
# s show the current problem
# none clear the selection
# r / t / e act on the current problem
# !cmd run a shell command in the problem dir
# q quit
# usaco new <name> [io-name] [--url <link>]
# Create solving/<name> from template.cpp
# (io-name sets freopen filenames, defaults to <name>)
# usaco run <name> Build main.cpp and run it (in the problem dir)
# usaco build <name> Build main.cpp only
# usaco done <name> Move solving/<name> -> solved/<name> and git commit
# usaco undo <name> Move solved/ or skipped/<name> -> solving/<name>
# usaco skip <name> Move solving/<name> -> skipped/<name>
# usaco io <name> [io-name] Show the problem's io name, or set it: renames <old>.in/.out
# and rewires STDIO("...") in main.cpp (adds it if missing)
# usaco cat <name> Print the problem's main.cpp to stdout (pipeable)
# usaco copy <name> Copy the problem's main.cpp to the clipboard (alias: cp)
# usaco vim <name> Open the problem's main.cpp in $EDITOR (aliases: edit, e)
# usaco open <name> Open the problem's saved URL in a browser
# usaco list List problems by status
# usaco stats Show solve counts and recent activity
# usaco path <name> Print the problem's directory (used by the ucd shell helper)
# usaco clean Delete compiled binaries and backups from all problem dirs
# usaco template <name> Re-copy template.cpp into the problem as main.cpp (backs up old one)
# usaco reset <name> Reset the solution: fresh main.cpp from template (STDIO wired up),
# delete binary + .out; keeps tests/ and .in (aliases: rm, delete)
# usaco test create <name> Save a test case: uses the current .in (or lets you paste one),
# then asks for the expected output. Stored in tests/N.in + N.out
# usaco test <name> [nums...] Build and run every saved test case (or just the given ones),
# diff against expected output, show pass/fail
#
# Short aliases: n=new r=run b=build t=test d=done u=undo sk=skip o=open
# l/ls=list st=stats p=path tpl=template e=edit=vim
#
# Names may be unique prefixes: 'usaco e diam' finds diamond-collector.
#
# Implementation: each command lives in lib/cmd/<name>.sh; shared helpers in lib/common.sh.
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
usage() { awk 'NR>1 { if (!/^#/) exit; sub(/^# ?/,""); print }' "$0"; exit 1; }
cmd="${1:-}"; shift || true
case "$cmd" in
interactive|i|repl) cmd=interactive ;;
new|n) cmd=new ;;
run|r) cmd=run ;;
build|b) cmd=build ;;
test|t) cmd=test ;;
done|d) cmd=done ;;
undo|u) cmd=undo ;;
skip|sk) cmd=skip ;;
io) cmd=io ;;
cat) cmd=cat ;;
copy|cp) cmd=copy ;;
vim|edit|e) cmd=edit ;;
open|o) cmd=open ;;
list|l|ls) cmd=list ;;
stats|st) cmd=stats ;;
path|p) cmd=path ;;
clean) cmd=clean ;;
template|tpl) cmd=template ;;
reset|rm|delete) cmd=reset ;;
*) usage ;;
esac
source "$ROOT/lib/common.sh"
source "$ROOT/lib/cmd/$cmd.sh"