"$@" would have worked just as well there, instead of the final three lines: you pulled cmd off the front just to... put it back. (I wouldn't recommend doing either of these, though, as it is weird that random other commands are valid there, such as "ls"; you should use a case statement.)
Yes, I think I used to check if `$cmd` was in a space separated list of valid commands, but I don't anymore because I only every use this to quickly get some commands down into a project's directory so as not to forget them.
As soon as any complexity or validation is needed I move to python, which is usually a better fit, and arguably even more portable.