def split_by_pipes(cmd):
    """
    Split the command by shell pipes, but preserve contents in 
    parentheses and braces. Also handles nested parens and braces.

    :param str cmd: Command to investigate.
    :return list: List of sub commands to be linked
    """
    stack_brace = []
    stack_paren = []
    cmdlist = []
    newcmd = str()
    for char in cmd:
        if char is '{':
            stack_brace.append('{')
        elif char is '}':
            stack_brace.pop()
        elif char is '(':
            stack_paren.append('(')
        elif char is ')':
            stack_paren.pop()
        if len(stack_brace) > 0 or len(stack_paren) > 0:
            newcmd += char
        elif char is '|':
            cmdlist.append(newcmd)
            newcmd = str()
            next
        else:
            newcmd += char
    cmdlist.append(newcmd)
    return cmdlist
