def printable_command(cmd):
    """Rebuild a command line from system arguments."""
    parts = []
    for part in cmd:
        if ' ' in part:
            has_double_quotes = '"' in part
            has_single_quotes = "'" in part
            if has_double_quotes and not has_single_quotes:
                part = f"'{part}'"
            elif has_single_quotes and has_double_quotes:
                part = part.replace('"', '\\"')
                part = f'"{part}"'
            else:
                part = f'"{part}"'
        parts.append(part)
    return ' '.join(parts)
