Esempio n. 1
0
def add_username_segment(powerline):
    import os
    if powerline.args.shell == 'bash':
        user_prompt = ' \\u '
    elif powerline.args.shell == 'zsh':
        user_prompt = ' %n '
    else:
        user_prompt = ' ' + os.environ[_as_bytes('USER')] + ' '

    if os.environ[_as_bytes('USER')] == 'root':
        bgcolor = Color.USERNAME_ROOT_BG
    else:
        bgcolor = Color.USERNAME_BG

    powerline.append(user_prompt, Color.USERNAME_FG, bgcolor)
Esempio n. 2
0
def add_username_segment(powerline):
  import os
  if powerline.args.shell == 'bash':
    user_prompt = ' \\u '
  elif powerline.args.shell == 'zsh':
    user_prompt = ' %n '
  else:
    user_prompt = ' ' + os.environ[_as_bytes('USER')] + ' '

  if os.environ[_as_bytes('USER')] == 'root':
    bgcolor = Color.USERNAME_ROOT_BG
  else:
    bgcolor = Color.USERNAME_BG

  powerline.append(user_prompt, Color.USERNAME_FG, bgcolor)
Esempio n. 3
0
def add_cwd_segment(powerline):
    cwd = powerline.cwd or os.environ[_as_bytes('PWD')]
    names = get_short_path(cwd.decode('utf-8'))

    max_depth = powerline.args.cwd_max_depth
    if len(names) > max_depth:
        i = 2 - max_depth
        assert i > 0
        names = names[:2] + [u'\u2026'] + names[i:]

    if not powerline.args.cwd_only:
        for n in names[:-1]:
            if n == u'~' and Color.HOME_SPECIAL_DISPLAY:
                powerline.append(' ' + n.encode('utf-8') + ' ', Color.HOME_FG,
                                 Color.HOME_BG)
            else:
                powerline.append(' ' + n.encode('utf-8') + ' ', Color.PATH_FG,
                                 Color.PATH_BG,
                                 powerline.separator_thin.encode('utf-8'),
                                 str(Color.SEPARATOR_FG))

    if names[-1] == u'~' and Color.HOME_SPECIAL_DISPLAY:
        powerline.append(' ' + names[-1].encode('utf-8') + ' ', Color.HOME_FG,
                         Color.HOME_BG)
    else:
        powerline.append(' ' + names[-1].encode('utf-8') + ' ', Color.CWD_FG,
                         Color.PATH_BG)
Esempio n. 4
0
def get_short_path(cwd):
    home = os.environ[_as_bytes('HOME')]
    names = cwd.split(sep)
    if names[0] == u'': names = names[1:]
    path = u''
    for i in range(len(names)):
        path += sep + names[i]
        if os.path.samefile(path.encode('utf-8'), home):
            return [u'~'] + names[i + 1:]
    if not names[0]:
        return [u'/']
    return names
Esempio n. 5
0
def get_short_path(cwd):
  home = os.environ[_as_bytes('HOME')]
  names = cwd.split(sep)
  if names[0] == u'': names = names[1:]
  path = u''
  for i in range(len(names)):
    path += sep + names[i]
    if os.path.samefile(path.encode('utf-8'), home):
      return [u'~'] + names[i+1:]
  if not names[0]:
    return [u'/']
  return names
Esempio n. 6
0
def get_valid_cwd():
    """ We check if the current working directory is valid or not. Typically
    happens when you checkout a different branch on git that doesn't have
    this directory.
    We return the original cwd because the shell still considers that to be
    the working directory, so returning our guess will confuse people
  """
    cwd = os.environ[_as_bytes('PWD')]
    parts = cwd.split(os.sep)
    up = cwd
    while parts and not os.path.exists(up):
        parts.pop()
        up = os.sep.join(parts)
    chdir(up)
    return cwd
Esempio n. 7
0
def get_valid_cwd():
  """ We check if the current working directory is valid or not. Typically
    happens when you checkout a different branch on git that doesn't have
    this directory.
    We return the original cwd because the shell still considers that to be
    the working directory, so returning our guess will confuse people
  """
  cwd = os.environ[_as_bytes('PWD')]
  parts = cwd.split(os.sep)
  up = cwd
  while parts and not os.path.exists(up):
    parts.pop()
    up = os.sep.join(parts)
  chdir(up)
  return cwd
Esempio n. 8
0
def add_cwd_segment(powerline):
  cwd = powerline.cwd or os.environ[_as_bytes('PWD')]
  names = get_short_path(cwd.decode('utf-8'))

  max_depth = powerline.args.cwd_max_depth
  if len(names) > max_depth:
    i = 2 - max_depth
    assert i > 0
    names = names[:2] + [u'\u2026'] + names[i:]

  if not powerline.args.cwd_only:
    for n in names[:-1]:
      if n == u'~' and Color.HOME_SPECIAL_DISPLAY:
        powerline.append(' ' + n.encode('utf-8') + ' ', Color.HOME_FG, Color.HOME_BG)
      else:
        powerline.append(' ' + n.encode('utf-8') + ' ', Color.PATH_FG, Color.PATH_BG, powerline.separator_thin.encode('utf-8'), str(Color.SEPARATOR_FG))

  if names[-1] == u'~' and Color.HOME_SPECIAL_DISPLAY:
    powerline.append(' ' + names[-1].encode('utf-8') + ' ', Color.HOME_FG, Color.HOME_BG)
  else:
    powerline.append(' ' + names[-1].encode('utf-8') + ' ', Color.CWD_FG, Color.PATH_BG)