Autocompleting Student Usernames in zsh
I use a lot of scripts to help me grade students’ work, enter their scores in the gradebook, and send them email reports. For example, I might grade the entire class’s work with:
./autograde "Homework 2" /path/to/submissions
Or maybe I just want to grade Quintin Buster’s submission. I just supply his username as a parameter:
./autograde "Homework 2" /path/to/submissions BUSTERQ
I’ve had an itch for a very long time to enable autocompletion of my students’ usernames, which I can almost never remember when I’m grading. I’ve now scratched that itch with zsh using compctl:
_ids() {
reply=(BUSTERQ USERNAME2 USERNAME3 USERNAME4)
}
compctl -f -K _ids autograde
This compctl command adds completion for the autograde script. The -f says to complete file names as parameters to autograde. The -K _ids says to also add the results of calling the _ids functions to the list of things that can be completed.
I threw these commands into a script in my gradebook directory, which I source when I’m ready to grade. Instead of assigning to reply a list of literal usernames, I read the usernames from a file I store for each class I teach.