Rewrite shellcmd to be cleaner & fail on subprocess errors.

Also refactor it into a library to avoid the current triplication.