Re-write the generated shell

Simplified, and in a way that makes more sense.