Files
usaco/usaco.zsh
T
adamfandClaude Opus 5.5 ac66ad6b03 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]>
2026-10-14 22:39:16 +01:00

89 lines
3.0 KiB
Bash

# usaco.zsh - zsh integration for the usaco script
# Source this from your ~/.zshrc:
# source ~/Coding/USACO/usaco.zsh
# Provides:
# - tab completion for commands and problem names
# - ucd <name>: cd into a problem's directory
USACO_ROOT="${0:A:h}"
usaco() { "$USACO_ROOT/usaco" "$@"; }
ucd() {
local dir
dir="$("$USACO_ROOT/usaco" path "$1")" || return 1
cd "$dir"
}
_usaco_problems() {
local -a names
names=("$USACO_ROOT"/{solving,solved,skipped}/*(N/:t))
_describe 'problem' names
}
_usaco() {
local -a cmds
cmds=(
'i:interactive mode (REPL with a current problem)'
'interactive:interactive mode (REPL with a current problem)'
'repl:interactive mode (REPL with a current problem)'
'new:create a problem from template'
'n:create a problem from template'
'run:build and run main.cpp'
'r:build and run main.cpp'
'build:build main.cpp'
'b:build main.cpp'
'vim:open main.cpp in $EDITOR'
'edit:open main.cpp in $EDITOR'
'e:open main.cpp in $EDITOR'
'test:run saved test cases (test create <name> to add one)'
't:run saved test cases'
'done:mark solved (auto-commits)'
'd:mark solved (auto-commits)'
'undo:move back to solving'
'u:move back to solving'
'skip:set aside for later'
'sk:set aside for later'
'io:show or set the freopen io name'
'cat:print main.cpp to stdout'
'copy:copy main.cpp to the clipboard'
'cp:copy main.cpp to the clipboard'
'open:open the saved problem URL'
'o:open the saved problem URL'
'list:list problems by status'
'l:list problems by status'
'ls:list problems by status'
'stats:show solve counts'
'st:show solve counts'
'path:print problem directory'
'p:print problem directory'
'clean:delete binaries and backups'
'sync:pull website edits, push local commits'
'sy:pull website edits, push local commits'
'template:same as reset'
'tpl:same as reset'
'reset:fresh main.cpp from template, delete binary/.out'
'rm:fresh main.cpp from template, delete binary/.out'
'delete:fresh main.cpp from template, delete binary/.out'
)
if (( CURRENT == 2 )); then
_describe 'command' cmds
elif (( CURRENT == 3 )); then
case "$words[2]" in
i|interactive|repl|new|n|list|l|ls|stats|st|clean|sync|sy) ;; # no problem-name argument
test|t)
local -a subs
subs=('create:save a new test case' 'add:save a new test case' 'new:save a new test case')
_describe 'subcommand' subs
_usaco_problems ;;
*) _usaco_problems ;;
esac
elif (( CURRENT == 4 )) && [[ "$words[2]" == (test|t) && "$words[3]" == (create|add|new) ]]; then
_usaco_problems
fi
}
if (( $+functions[compdef] )); then
compdef _usaco usaco
compdef _usaco_problems ucd
fi