Update terminal segments and default theme

This commit is contained in:
Kim Silkebækken 2013-01-09 14:29:44 +01:00
parent 44fb24dee6
commit 2ceec25713
2 changed files with 56 additions and 5 deletions

View File

@ -1,11 +1,48 @@
# -*- coding: utf-8 -*-
import os
import re
import socket
from powerline.lib.vcs import guess
def user_name():
user_name = os.environ.get('USER')
def hostname():
if not os.environ.get('SSH_CLIENT'):
return None
return socket.gethostname()
def user():
user = os.environ.get('USER')
euid = os.geteuid()
return {
'contents': user_name,
'highlight': 'user_name' if user_name != 'root' else ['user_name_root', 'user_name'],
'contents': user,
'highlight': 'user' if euid != 0 else ['superuser', 'user'],
}
def branch():
repo = guess(os.path.abspath(os.getcwd()))
if repo:
return repo.branch()
return None
def cwd(dir_shorten_len=None, dir_limit_depth=None):
cwd = os.getcwdu()
home = os.environ.get('HOME')
if home:
cwd = re.sub('^' + re.escape(home), '~', cwd, 1)
cwd_split = cwd.split(os.sep)
cwd_split_len = len(cwd_split)
if cwd_split_len > dir_limit_depth + 1:
del(cwd_split[0:-dir_limit_depth])
cwd_split.insert(0, u'')
cwd = [i[0:dir_shorten_len] if dir_shorten_len and i else i for i in cwd_split[:-1]] + [cwd_split[-1]]
cwd = os.path.join(*cwd)
return cwd

View File

@ -3,7 +3,21 @@
"segments": {
"left": [
{
"name": "user_name"
"name": "hostname",
"before": " "
},
{
"name": "user"
},
{
"name": "branch",
"before": " "
},
{
"name": "cwd",
"args": {
"dir_limit_depth": 3
}
}
]
}