mirror of
https://github.com/powerline/powerline.git
synced 2025-07-22 21:35:14 +02:00
Move terminal and tmux segments into common module
This should ideally be renamed to something else since it's not strictly an extension. A better module naming scheme could be something like: powerline.segments.ext.{extension} powerline.segments.common This would move all segments out of their respective extension directory, and might be a bit confusing. The ext directories may also need some changes to make this work properly.
This commit is contained in:
parent
78e54e0c84
commit
65e358dee2
0
powerline/ext/common/__init__.py
Normal file
0
powerline/ext/common/__init__.py
Normal file
@ -1,7 +1,10 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
import re
|
||||
import socket
|
||||
|
||||
from powerline.lib.vcs import guess
|
||||
from powerline.lib import memoize
|
||||
|
||||
# Weather condition code descriptions available at http://developer.yahoo.com/weather/#codes
|
||||
@ -18,6 +21,43 @@ weather_conditions_codes = {
|
||||
}
|
||||
|
||||
|
||||
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,
|
||||
'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
|
||||
|
||||
|
||||
def date(format='%Y-%m-%d'):
|
||||
from datetime import datetime
|
||||
return datetime.now().strftime(format)
|
@ -1,44 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
import re
|
||||
import socket
|
||||
|
||||
from powerline.lib.vcs import guess
|
||||
|
||||
|
||||
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,
|
||||
'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
|
@ -1,4 +1,5 @@
|
||||
{
|
||||
"default_module": "powerline.ext.common.segments",
|
||||
"segments": {
|
||||
"left": [
|
||||
{
|
||||
|
@ -1,8 +1,8 @@
|
||||
{
|
||||
"default_module": "powerline.ext.common.segments",
|
||||
"segments": {
|
||||
"left": [
|
||||
{
|
||||
"module": "powerline.ext.terminal.segments",
|
||||
"name": "user"
|
||||
},
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user