# acad — fish integration
# Drop this file in ~/.config/fish/conf.d/ (it will be auto-sourced on shell start).
#
# Provides:
#   - `grades` alias (shorthand for `acad grades`)
#   - `uni <subcommand>` — verb-first wrapper that delegates to `acad`, plus a few
#     conveniences (git save, search across notes, fzf course selector).
#
# Requires:
#   - `acad` on PATH  (installed via `pipx install acad`)
#   - UNI_ROOT env var pointing at your academic content directory
#     (set by `acad init`, or manually: `set -gx UNI_ROOT ~/academic`)

# Shorthand alias for the grades subcommand
alias grades='acad grades'


# Note: `uni compile` and `uni fig` call companion scripts that aren't yet folded
# into acad — `compile_master.py` (master file assembly) and `ipe-figures.py`
# (Ipe figure pipeline). Drop those into $UNI_ROOT/scripts/ if you want those
# subcommands working, or just ignore them. They'll be merged into acad in a
# future release.

function uni --description "Unified university command system"
    switch $argv[1]
        # Lecture management
        case lecture new-lecture lec
            if test (count $argv) -lt 2
                echo "Usage: uni lecture <course> [title] [extra flags]"
                return 1
            end
            if test (count $argv) -ge 3
                acad new -c "$argv[2]" -t "$argv[3]" $argv[4..]
            else
                acad new -c "$argv[2]"
            end

        # Compile master PDF
        case compile build master
            if test (count $argv) -lt 2
                echo "Usage: uni compile <course>"
                echo "Available courses:"
                ls -d $UNI_ROOT/*/ | grep -v -E 'scripts|templates|planning|psets' | xargs -n1 basename
                return 1
            end
            python3 $UNI_ROOT/scripts/compile_master.py $argv[2..]

            # Grade management
        case grade grades gpa
            acad grades $argv[2..]

            # Search across all notes
        case search find grep
            if test (count $argv) -lt 2
                echo "Usage: uni search <keyword>"
                return 1
            end
            set keyword $argv[2..]
            cd $UNI_ROOT
            echo "🔍 Searching for '$keyword'..."
            echo ""
            grep -r --include="*.tex" --color=always -n "$keyword" . | grep -v -E '\.aux|\.log|\.toc|preamble.tex' | head -30

            # Statistics dashboard
        case stats statistics dashboard
            acad dashboard

        # Git save
        case save push commit
            save-uni $argv[2..]

            # Git status
        case status st
            cd $UNI_ROOT
            echo "📁 University Repository Status"
            echo "================================"
            git status

            # List courses
        case list courses ls
            acad list

            # Clean auxiliary files
        case clean cleanup
            if test (count $argv) -ge 2
                acad course cleanup --name $argv[2]
            else
                acad course cleanup
            end

            # Help
        case fig figure
            python3 $UNI_ROOT/scripts/ipe-figures.py $argv[2..]

        case help -h --help
            echo "uni - Unified University Command System"
            echo ""
            echo "Usage: uni <command> [arguments]"
            echo ""
            echo "Commands:"
            echo "  lecture <course> <title>   Create new lecture"
            echo "  compile <course>           Compile master PDF"
            echo "  grade                      Manage grades"
            echo "  fig <name>                 Create/edit figure"
            echo "  search <keyword>           Search all notes"
            echo "  stats                      Show statistics dashboard"
            echo "  save [message]             Push to GitHub"
            echo "  status                     Show git status"
            echo "  list                       List all courses"
            echo "  clean <course>             Remove auxiliary files"
            echo ""
            echo "Examples:"
            echo "  uni lecture math55 'Group Theory'"
            echo "  uni compile math55"
            echo "  uni search 'symmetric group'"
            echo "  uni stats"
            echo "  uni save 'Added lecture 9'"

        case '*'
            echo "❌ Unknown command: $argv[1]"
            echo "Run 'uni help' for usage information"
    end
end


# Quick shortcuts (optional)
alias unil='uni lecture'
alias unic='uni compile'
alias unis='uni search'
alias unist='uni stats'
