#!/usr/bin/env bash set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" VENV_PYTHON="$SCRIPT_DIR/.venv/bin/python3" if [ -f "$SCRIPT_DIR/.env" ]; then # shellcheck source=/dev/null source "$SCRIPT_DIR/.env" fi init_paper() { local raw="${1:-.}" local name name="$(printf '%s' "$raw" | tr '[:upper:]' '[:lower:]' | tr -d '\\' | tr '[:space:]' '_')" local dest="$SCRIPT_DIR/$name" if [ -d "$dest" ]; then echo "Error: '$dest' already exists" >&2 exit 1 fi mkdir -p "$dest" cp "$SCRIPT_DIR/ams-latex-template/doc/amsart-template.tex" "$dest/paper.tex" sed -i '' "s|\\\\title{}|\\\\title{$raw}|" "$dest/paper.tex" sed -i '' "s|\\\\author{}|\\\\author{Eric Bauerfeld}|" "$dest/paper.tex" sed -i '' '/^% author two information$/,/^\\thanks{}$/d' "$dest/paper.tex" echo "Initialized paper.tex in $dest" } setup() { local sage_python_path="${1:-${SAGE_PYTHON_PATH:?Usage: setup }}" local sage_site_packages="${2:-${SAGE_SITE_PACKAGES:?Usage: setup }}" local system_name="${3:-$(hostname -s)}" printf 'SAGE_PYTHON_PATH=%s\nSAGE_SITE_PACKAGES=%s\n' "$sage_python_path" "$sage_site_packages" \ >"$SCRIPT_DIR/.env.$system_name" ln -sf ".env.$system_name" "$SCRIPT_DIR/.env" source "$SCRIPT_DIR/.env" mkdir -p "$SCRIPT_DIR/.vscode" "$sage_python_path" - <subcmd' \ '*: :->args' case $state in subcmd) local subcmds=( 'init_paper:Initialize a new paper directory from the AMS template' 'setup:Configure Python/Sage environment and install dependencies' 'sage:Run sage with plantri available on PATH' 'lint:Run pyright and pylint on lib/' 'completion:Output shell completion code' ) _describe 'subcommand' subcmds ;; args) case $words[2] in init_paper) _message 'paper title (spaces become underscores)' ;; setup) case $((CURRENT - 2)) in 1) _files ;; 2) _files -/ ;; 3) _message 'system name (e.g. macbook, workstation)' ;; esac ;; sage) _files ;; lint) _files ;; completion) _values 'shell' 'zsh' ;; esac ;; esac } compdef _run_sh run.sh EOF ;; *) echo "Unsupported shell: $shell. Supported: zsh" >&2 exit 1 ;; esac } case "${1:-}" in init_paper) shift init_paper "$@" ;; setup) shift setup "$@" ;; sage) shift run_sage "$@" ;; lint) shift lint "$@" ;; completion) shift completion "$@" ;; *) echo "Usage: $0 {init_paper|setup|sage|lint|completion} [args]" >&2 exit 1 ;; esac