import sh


def build_sh_cmd(cmd, cwd=None):
    """Build a `sh.Command` from a string.

    :param cmd: String with the command to convert.
    :param cwd: Optional path to use as working directory.
    :return: `sh.Command`
    """
    args = cmd.split()
    return getattr(sh, args[0]).bake(_cwd=cwd, *args[1:])