def add_term_title_segment():
    term = os.getenv('TERM')
    if not (('xterm' in term) or ('rxvt' in term)):
        return

    if powerline.args.shell == 'bash':
        set_title = '\\[\\e]0;\\u@\\h: \\w\\a\\]'
    elif powerline.args.shell == 'zsh':
        set_title = '\\e]0;%n@%m: %~\\a'
    else:
        import socket
        set_title = '\\e]0;%s@%s: %s\\a' % (os.getenv('USER'), socket.gethostname().split('.')[0], powerline.cwd or os.getenv('PWD'))

    powerline.append(set_title, None, None, '')


add_term_title_segment()

def add_term_title_segment():
    term = os.getenv('TERM')
    if not (('xterm' in term) or ('rxvt' in term)):
        return

    if powerline.args.shell == 'bash':
        set_title = '\\[\\e]0;\\u@\\h: \\w\\a\\]'
    elif powerline.args.shell == 'zsh':
        set_title = '\033]0;%n@%m: %~\007'
    else:
        import socket
        set_title = '\033]0;%s@%s: %s\007' % (os.getenv('USER'), socket.gethostname().split('.')[0], powerline.cwd or os.getenv('PWD'))

    powerline.append(set_title, None, None, '')


add_term_title_segment()

Fix use of escape characters in "set terminal title" segment.
Fix use of escape characters in "set terminal title" segment.

Escape characters were incorrect for non-BASH shells.

  def add_term_title_segment():
      term = os.getenv('TERM')
      if not (('xterm' in term) or ('rxvt' in term)):
          return
  
      if powerline.args.shell == 'bash':
          set_title = '\\[\\e]0;\\u@\\h: \\w\\a\\]'
      elif powerline.args.shell == 'zsh':
-         set_title = '\\e]0;%n@%m: %~\\a'
+         set_title = '\033]0;%n@%m: %~\007'
      else:
          import socket
-         set_title = '\\e]0;%s@%s: %s\\a' % (os.getenv('USER'), socket.gethostname().split('.')[0], powerline.cwd or os.getenv('PWD'))
+         set_title = '\033]0;%s@%s: %s\007' % (os.getenv('USER'), socket.gethostname().split('.')[0], powerline.cwd or os.getenv('PWD'))
  
      powerline.append(set_title, None, None, '')
  
  
  add_term_title_segment()
  
Fix use of escape characters in "set terminal title" segment.
## Code Before:
def add_term_title_segment():
    term = os.getenv('TERM')
    if not (('xterm' in term) or ('rxvt' in term)):
        return

    if powerline.args.shell == 'bash':
        set_title = '\\[\\e]0;\\u@\\h: \\w\\a\\]'
    elif powerline.args.shell == 'zsh':
        set_title = '\\e]0;%n@%m: %~\\a'
    else:
        import socket
        set_title = '\\e]0;%s@%s: %s\\a' % (os.getenv('USER'), socket.gethostname().split('.')[0], powerline.cwd or os.getenv('PWD'))

    powerline.append(set_title, None, None, '')


add_term_title_segment()

## Instruction:
Fix use of escape characters in "set terminal title" segment.
## Code After:
def add_term_title_segment():
    term = os.getenv('TERM')
    if not (('xterm' in term) or ('rxvt' in term)):
        return

    if powerline.args.shell == 'bash':
        set_title = '\\[\\e]0;\\u@\\h: \\w\\a\\]'
    elif powerline.args.shell == 'zsh':
        set_title = '\033]0;%n@%m: %~\007'
    else:
        import socket
        set_title = '\033]0;%s@%s: %s\007' % (os.getenv('USER'), socket.gethostname().split('.')[0], powerline.cwd or os.getenv('PWD'))

    powerline.append(set_title, None, None, '')


add_term_title_segment()
