Merge branch 'feature/tmux' into develop

Closes #41.
Closes #43.
Closes #44.
This commit is contained in:
Kim Silkebækken 2013-01-16 08:23:49 +01:00
commit 28aaed0c77
7 changed files with 168 additions and 12 deletions

View File

@ -4,12 +4,22 @@
Run with `tmux -f tmux.conf`.
'''
import argparse
import os
import sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
from powerline.core import Powerline
pl = Powerline('tmux')
print(pl.renderer.render('n').encode('utf-8'))
parser = argparse.ArgumentParser(description='powerline outputter')
parser.add_argument('side', nargs='?', default='all', choices=('all', 'left', 'right'))
parser.add_argument('--ext', default='tmux')
if __name__ == '__main__':
args = parser.parse_args()
pl = Powerline(args.ext)
segments = pl.renderer.get_theme().get_segments()
if args.side != 'all':
segments = [s for s in segments if s['side'] == args.side]
print(pl.renderer.render('n', segments=segments).encode('utf-8'))

View File

@ -2,4 +2,9 @@ set-option -g status on
set-option -g status-interval 2
set-option -g status-utf8 on
set-option -g status-left-length 100
set-option -g status-left "#(./pl.py)"
set-option -g status-left "#(./pl.py left)"
set-option -g status-right-length 100
set-option -g status-right "#(./pl.py right)"
set-option -g status-justify "centre"
set-option -g status-bg "colour235"
set-option -g status-fg "colour249"

View File

@ -0,0 +1,29 @@
{
"name": "Default color scheme for terminal prompts",
"colors": {
"black": 16,
"white": 231,
"darkestblue": 24,
"darkblue": 31,
"mediumblue": 38,
"brightblue": 117,
"brightestblue": 153,
"green": 148,
"yellow": 220,
"red": 202
},
"groups": {
"user": { "fg": "white", "bg": "mediumblue", "attr": ["bold"] },
"date": { "fg": "white", "bg": "mediumblue" },
"forecast": { "fg": "brightestblue", "bg": "darkblue" },
"external_ip": { "fg": "brightestblue", "bg": "darkblue" },
"system_load": { "fg": "brightblue", "bg": "darkestblue" },
"system_load_good": { "fg": "green", "bg": "darkestblue" },
"system_load_bad": { "fg": "yellow", "bg": "darkestblue" },
"system_load_ugly": { "fg": "red", "bg": "darkestblue" },
"uptime": { "fg": "brightblue", "bg": "darkestblue" }
},
"mode_translations": { }
}

View File

@ -17,11 +17,11 @@
"theme": "default"
},
"tmux": {
"colorscheme": "default",
"colorscheme": "tmux_default",
"theme": "default"
},
"vim": {
"colorscheme": "default",
"colorscheme": "vim_default",
"theme": "default",
"local_themes": {
"help": "help"

View File

@ -2,10 +2,94 @@
import os
from powerline.lib.memoize import memoize
def user_name():
user_name = os.environ.get('USER')
# Weather condition code descriptions available at http://developer.yahoo.com/weather/#codes
weather_conditions_codes = {
u'': [25, 34],
u'': [24],
u'': [5, 6, 8, 9, 10, 11, 12, 35, 40, 45, 47],
u'': range(26, 30) + [44],
u'': [7] + range(13, 18) + [41, 42, 43, 46],
u'': range(0, 4) + range(37, 39),
u'': range(19, 23),
u'': [32, 36],
u'': [31, 33],
}
def date(format='%Y-%m-%d'):
from datetime import datetime
return datetime.now().strftime(format)
@memoize(600, persistent=True)
def external_ip(query_url='http://icanhazip.com/'):
import urllib2
try:
return urllib2.urlopen(query_url).read().strip()
except urllib2.HTTPError:
return
def system_load(format='{avg[0]:.1f}, {avg[1]:.1f}, {avg[2]:.1f}'):
from multiprocessing import cpu_count
averages = os.getloadavg()
normalized = averages[1] / cpu_count()
if normalized < 1:
gradient = 'system_load_good'
elif normalized < 2:
gradient = 'system_load_bad'
else:
gradient = 'system_load_ugly'
return {
'contents': user_name,
'highlight': 'user_name' if user_name != 'root' else ['user_name_root', 'user_name'],
}
'contents': format.format(avg=averages),
'highlight': [gradient, 'system_load']
}
def uptime(format='{days:02d}d {hours:02d}h {minutes:02d}m'):
# TODO: make this work with operating systems without /proc/uptime
try:
with open('/proc/uptime', 'r') as f:
seconds = int(float(f.readline().split()[0]))
minutes, seconds = divmod(seconds, 60)
hours, minutes = divmod(minutes, 60)
days, hours = divmod(hours, 24)
return format.format(days=int(days), hours=hours, minutes=minutes)
except IOError:
pass
@memoize(600, persistent=True)
def forecast(unit='c', location_query=None):
import json
import urllib
import urllib2
if not location_query:
try:
location = json.loads(urllib2.urlopen('http://freegeoip.net/json/' + external_ip()).read())
location_query = ','.join([location['city'], location['region_name'], location['country_name']])
except ValueError:
return None
query_data = {
'q':
'use "http://github.com/yql/yql-tables/raw/master/weather/weather.bylocation.xml" as we;'
'select * from we where location="{0}" and unit="{1}"'.format(location_query, unit),
'format': 'json'
}
url = 'http://query.yahooapis.com/v1/public/yql?' + urllib.urlencode(query_data)
response = json.loads(urllib2.urlopen(url).read())
condition = response['query']['results']['weather']['rss']['channel']['item']['condition']
condition_code = int(condition['code'])
icon = u''
for icon, codes in weather_conditions_codes.items():
if condition_code in codes:
break
return u'{0} {1}°{2}'.format(icon, condition['temp'], unit.upper())

View File

@ -2,7 +2,35 @@
"segments": {
"left": [
{
"name": "user_name"
"module": "powerline.ext.terminal.segments",
"name": "user"
},
{
"name": "external_ip",
"before": "ⓦ "
},
{
"name": "uptime",
"before": "⇑ "
}
],
"right": [
{
"name": "system_load"
},
{
"name": "forecast"
},
{
"name": "date",
"args": {"format": "%a"}
},
{
"name": "date"
},
{
"name": "date",
"args": {"format": "%H:%M"}
}
]
}