# 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 : 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=( 'new:create a problem from template' 'run:build and run main.cpp' 'build:build main.cpp' 'vim:open main.cpp in $EDITOR' 'edit:open main.cpp in $EDITOR' 'e:open main.cpp in $EDITOR' 'done:mark solved (auto-commits)' 'undo:move back to solving' 'skip:set aside for later' 'open:open the saved problem URL' 'list:list problems by status' 'stats:show solve counts' 'path:print problem directory' 'clean:delete binaries and backups' 'template:reset main.cpp from template' ) if (( CURRENT == 2 )); then _describe 'command' cmds elif (( CURRENT == 3 )); then case "$words[2]" in new|list|stats|clean) ;; *) _usaco_problems ;; esac fi } if (( $+functions[compdef] )); then compdef _usaco usaco compdef _usaco_problems ucd fi