Pull out ugly 'command -v' code to a utility function