bash completion: rewrite for great justice

This is a lot more verbose, but I actually understand my own code now.