Tidy the usaco CLI: prefixes everywhere, LOCAL debug builds, git-based dates
- done/skip/undo accept unique prefixes like every other command - builds define LOCAL (-I repo root): the template includes debugging.h and enables DBG/printV only locally, so main.cpp is submittable as-is - run/build/test --debug (or USACO_DEBUG=1): ASan/UBSan + _GLIBCXX_DEBUG - list/stats date problems by git history, not mtimes reset by checkouts - template/tpl is now an alias of reset (which gains -y); fixes template dropping the STDIO line - run shows <io>.out via detect_io instead of the first *.out - debugging.h: size_t loop indices (no -Wsign-compare noise) - zsh completion for i/cat/copy; README covers test, io, reset, --debug - ignore a.out Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
+2
-2
@@ -1,7 +1,7 @@
|
||||
# usaco done <name>
|
||||
[[ $# -ge 1 ]] || usage
|
||||
name="$1"
|
||||
[[ -d "$ROOT/solving/$name" ]] || { echo "Error: solving/$name not found" >&2; exit 1; }
|
||||
dir="$(find_problem "$1")"; name="$(basename "$dir")"
|
||||
[[ "$dir" == "$ROOT/solving/$name" ]] || { echo "Error: $name is not in solving/ (it's in ${dir#$ROOT/})" >&2; exit 1; }
|
||||
[[ -d "$ROOT/solved/$name" ]] && { echo "Error: solved/$name already exists" >&2; exit 1; }
|
||||
mv "$ROOT/solving/$name" "$ROOT/solved/$name"
|
||||
echo "Moved to solved/$name 🎉"
|
||||
|
||||
@@ -8,7 +8,7 @@ STACK_FILE="$ROOT/.current_stack"
|
||||
HISTFILE="$ROOT/.usaco_history"
|
||||
|
||||
# commands that take a problem name (the selection is injected when you omit it)
|
||||
WITH_PROBLEM="run build test done undo skip io cat copy edit open path template reset"
|
||||
WITH_PROBLEM="run build test done undo skip io cat copy edit open path reset"
|
||||
# commands that take no problem
|
||||
NO_PROBLEM="list stats clean sync"
|
||||
# REPL-only words (used for completion and for 'help')
|
||||
@@ -144,7 +144,7 @@ while :; do
|
||||
case "$c" in
|
||||
r) c=run ;; b) c=build ;; t) c=test ;; d) c=done ;; u) c=undo ;; sk) c=skip ;;
|
||||
e|vim) c=edit ;; o) c=open ;; l|ls) c=list ;; st) c=stats ;; p) c=path ;;
|
||||
tpl) c=template ;; rm|delete) c=reset ;; cp) c=copy ;; sy) c=sync ;;
|
||||
tpl|template|rm|delete) c=reset ;; cp) c=copy ;; sy) c=sync ;;
|
||||
esac
|
||||
|
||||
if [[ " $NO_PROBLEM " == *" $c "* ]]; then
|
||||
@@ -155,7 +155,7 @@ while :; do
|
||||
if [[ " $WITH_PROBLEM " == *" $c "* ]]; then
|
||||
# 'test create' keeps its subword first; the name goes after it
|
||||
pre=(); if [[ "$c" == test && "${args[0]:-}" =~ ^(create|add|new)$ ]]; then pre=("${args[0]}"); args=("${args[@]:1}"); fi
|
||||
if [[ ${#args[@]} -ge 1 ]]; then # explicit name: use it and switch to it
|
||||
if [[ ${#args[@]} -ge 1 && "${args[0]}" != -* ]]; then # explicit name: use it and switch to it
|
||||
n="$(real_name "${args[0]}")" || { find_problem "${args[0]}" >/dev/null || true; continue; }
|
||||
set_current "$n"; args=("${args[@]:1}")
|
||||
elif [[ -z "$cur" ]]; then
|
||||
|
||||
+1
-2
@@ -3,8 +3,7 @@ list_by_mtime() { # list subdirs of $1 oldest-first by last modification
|
||||
[[ -d "$1" ]] || return 0
|
||||
for d in "$1"/*/; do
|
||||
[[ -d "$d" ]] || continue
|
||||
# newest mtime of any file in the problem dir
|
||||
printf '%s\t%s\n' "$(find "$d" -type f -printf '%T@\n' | sort -n | tail -1)" "$(basename "$d")"
|
||||
printf '%s\t%s\n' "$(last_touched "${d%/}")" "$(basename "$d")"
|
||||
done | sort -n | cut -f2 | sed 's/^/ /'
|
||||
}
|
||||
echo "== Solving =="
|
||||
|
||||
+8
-6
@@ -1,14 +1,16 @@
|
||||
# usaco reset/rm/delete <name>
|
||||
# usaco reset/rm/delete/template/tpl <name> [-y]
|
||||
[[ $# -ge 1 ]] || usage
|
||||
dir="$(find_problem "$1")"
|
||||
name="$(basename "$dir")"
|
||||
io="$(detect_io "$dir" || true)"
|
||||
io="${io:-$name}"
|
||||
echo "This resets ${dir#$ROOT/} to a fresh template:"
|
||||
echo " main.cpp -> re-created from template (old one saved as main.cpp.bak)"
|
||||
echo " removes compiled binary and $io.out (tests/ and $io.in are kept)"
|
||||
read -r -p "Reset '$name'? [y/N] " ans
|
||||
[[ "$ans" == y || "$ans" == Y ]] || { echo "Aborted."; exit 1; }
|
||||
if [[ "${2:-}" != -y ]]; then
|
||||
echo "This resets ${dir#$ROOT/} to a fresh template:"
|
||||
echo " main.cpp -> re-created from template (old one saved as main.cpp.bak)"
|
||||
echo " removes compiled binary and $io.out (tests/ and $io.in are kept)"
|
||||
read -r -p "Reset '$name'? [y/N] " ans
|
||||
[[ "$ans" == y || "$ans" == Y ]] || { echo "Aborted."; exit 1; }
|
||||
fi
|
||||
[[ -f "$dir/main.cpp" ]] && cp "$dir/main.cpp" "$dir/main.cpp.bak"
|
||||
fresh_main "$dir" "$io"
|
||||
rm -f "$dir/main" "$dir/a.out" "$dir/$io.out"
|
||||
|
||||
+4
-4
@@ -5,8 +5,8 @@ build_problem "$dir"
|
||||
# run from inside the dir so freopen finds the .in file
|
||||
(cd "$dir" && ./main)
|
||||
# show the .out file if the program wrote one
|
||||
out="$(ls "$dir"/*.out 2>/dev/null | grep -v '/a\.out$' | head -1 || true)"
|
||||
if [[ -n "$out" ]]; then
|
||||
echo "── $(basename "$out") ──"
|
||||
cat "$out"
|
||||
io="$(detect_io "$dir" || true)"
|
||||
if [[ -n "$io" && -f "$dir/$io.out" ]]; then
|
||||
echo "── $io.out ──"
|
||||
cat "$dir/$io.out"
|
||||
fi
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
# usaco skip <name>
|
||||
[[ $# -ge 1 ]] || usage
|
||||
name="$1"
|
||||
[[ -d "$ROOT/solving/$name" ]] || { echo "Error: solving/$name not found" >&2; exit 1; }
|
||||
dir="$(find_problem "$1")"; name="$(basename "$dir")"
|
||||
[[ "$dir" == "$ROOT/solving/$name" ]] || { echo "Error: $name is not in solving/ (it's in ${dir#$ROOT/})" >&2; exit 1; }
|
||||
[[ -d "$ROOT/skipped/$name" ]] && { echo "Error: skipped/$name already exists" >&2; exit 1; }
|
||||
mkdir -p "$ROOT/skipped"
|
||||
mv "$ROOT/solving/$name" "$ROOT/skipped/$name"
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ now=$(date +%s); week=0; month=0
|
||||
if [[ -d "$ROOT/solved" ]]; then
|
||||
for d in "$ROOT/solved"/*/; do
|
||||
[[ -d "$d" ]] || continue
|
||||
t="$(find "$d" -type f -printf '%T@\n' | sort -n | tail -1 | cut -d. -f1)"
|
||||
t="$(solved_at "${d%/}")"
|
||||
[[ -z "$t" ]] && continue
|
||||
age=$(( now - t ))
|
||||
(( age <= 7*86400 )) && week=$((week+1))
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
# usaco template/tpl <name>
|
||||
[[ $# -ge 1 ]] || usage
|
||||
dir="$(find_problem "$1")"
|
||||
[[ -f "$dir/main.cpp" ]] && cp "$dir/main.cpp" "$dir/main.cpp.bak" && echo "Backed up old main.cpp -> main.cpp.bak"
|
||||
cp "$ROOT/template.cpp" "$dir/main.cpp"
|
||||
echo "Refreshed $dir/main.cpp from template"
|
||||
+3
-5
@@ -1,10 +1,8 @@
|
||||
# usaco undo <name>
|
||||
[[ $# -ge 1 ]] || usage
|
||||
name="$1"; from=""
|
||||
for s in solved skipped; do
|
||||
[[ -d "$ROOT/$s/$name" ]] && from="$s" && break
|
||||
done
|
||||
[[ -n "$from" ]] || { echo "Error: '$name' not found in solved/ or skipped/" >&2; exit 1; }
|
||||
dir="$(find_problem "$1")"; name="$(basename "$dir")"
|
||||
from="$(basename "$(dirname "$dir")")"
|
||||
[[ "$from" != solving ]] || { echo "Error: $name is already in solving/" >&2; exit 1; }
|
||||
[[ -d "$ROOT/solving/$name" ]] && { echo "Error: solving/$name already exists" >&2; exit 1; }
|
||||
mv "$ROOT/$from/$name" "$ROOT/solving/$name"
|
||||
echo "Moved back to solving/$name (was $from)"
|
||||
|
||||
Reference in New Issue
Block a user