Merge remote-tracking branch 'zyx-i/powerline-daemon' into develop

This commit is contained in:
Kim Silkebækken 2013-05-06 15:37:44 +02:00
commit 4d5d92dda2
10 changed files with 57 additions and 19 deletions

View File

@ -1,11 +1,17 @@
_powerline_tmux_setenv() {
if [[ -n "$TMUX" ]]; then
tmux setenv TMUX_"$1"_$(tmux display -p "#D" | tr -d %) "$2"
tmux setenv -g TMUX_"$1"_$(tmux display -p "#D" | tr -d %) "$2"
tmux refresh -S
fi
}
POWERLINE_SAVED_PWD=
_powerline_tmux_set_pwd() {
_powerline_tmux_setenv PWD "$PWD"
if test "x$POWERLINE_SAVED_PWD" != "x$PWD" ; then
POWERLINE_SAVED_PWD="$PWD"
_powerline_tmux_setenv PWD "$PWD"
fi
}
_powerline_tmux_set_columns() {
@ -18,6 +24,7 @@ _powerline_prompt() {
eval $POWERLINE_OLD_PROMPT_COMMAND
PS1="$(powerline shell left -r bash_prompt --last_exit_code=$last_exit_code)"
_powerline_tmux_set_pwd
return $last_exit_code
}
trap "_powerline_tmux_set_columns" SIGWINCH

View File

@ -5,7 +5,7 @@ set -g status-fg colour231
set -g status-bg colour234
set -g status-left-length 20
set -g status-left '#[fg=colour16,bg=colour254,bold] #S #[fg=colour254,bg=colour234,nobold]#(powerline tmux left)'
set -g status-right '#(powerline tmux right)'
set -g status-right '#(powerline tmux right -R pane_id=`tmux display -p "#D"`)'
set -g status-right-length 150
set -g window-status-format "#[fg=colour244,bg=colour234]#I #[fg=colour240] #[fg=colour249]#W "
set -g window-status-current-format "#[fg=colour234,bg=colour31]#[fg=colour117,bg=colour31] #I  #[fg=colour231,bold]#W #[fg=colour31,bg=colour234,nobold]"

View File

@ -1,7 +1,8 @@
_powerline_tmux_setenv() {
emulate -L zsh
if [[ -n "$TMUX" ]]; then
tmux setenv TMUX_"$1"_$(tmux display -p "#D" | tr -d %) "$2"
tmux setenv -g TMUX_"$1"_$(tmux display -p "#D" | tr -d %) "$2"
tmux refresh -S
fi
}

View File

@ -44,7 +44,11 @@ def keyvaluesplit(s):
raise ValueError('Option names must not start with `_\'')
idx = s.index('=')
o = s[:idx]
val = json.loads(s[idx + 1:])
rest = s[idx + 1:]
if rest[0] in '"{[0193456789' or rest in ('null', 'true', 'false'):
val = json.loads(s[idx + 1:])
else:
val = rest
return (o, val)

View File

@ -2,6 +2,7 @@
from powerline.lib.threaded import MultiRunnedThread
from powerline.lib.file_watcher import create_file_watcher
from copy import deepcopy
from threading import Event, Lock
from collections import defaultdict
@ -103,10 +104,10 @@ class ConfigLoader(MultiRunnedThread):
def load(self, path):
try:
# No locks: GIL does what we need
return self.loaded[path]
return deepcopy(self.loaded[path])
except KeyError:
r = self._load(path)
self.loaded[path] = r
self.loaded[path] = deepcopy(r)
return r
def update(self):
@ -140,7 +141,7 @@ class ConfigLoader(MultiRunnedThread):
self.missing.pop(key)
for path in toload:
try:
self.loaded[path] = self._load(path)
self.loaded[path] = deepcopy(self._load(path))
except Exception as e:
self.exception('Error while loading {0}: {1}', path, str(e))

View File

@ -40,5 +40,15 @@ class TmuxRenderer(Renderer):
tmux_attr += ['nounderscore']
return '#[' + ','.join(tmux_attr) + ']'
def get_segment_info(self, segment_info):
r = self.segment_info.copy()
if segment_info:
r.update(segment_info)
if 'pane_id' in r:
varname = 'TMUX_PWD_' + r['pane_id'].lstrip('%')
if varname in r['environ']:
r['getcwd'] = lambda: r['environ'][varname]
return r
renderer = TmuxRenderer

View File

@ -7,8 +7,9 @@ from powerline.lib import mergedicts, parsedotval
def mergeargs(argvalue):
if not argvalue:
return None
r = dict([argvalue[0]])
for subval in argvalue[1:]:
argvalue = iter(argvalue)
r = dict([next(argvalue)])
for subval in argvalue:
mergedicts(r, dict([subval]))
return r
@ -16,13 +17,13 @@ def mergeargs(argvalue):
class ShellPowerline(Powerline):
def __init__(self, args, **kwargs):
self.args = args
self.theme_option = mergeargs(args.theme_option) or {}
self.theme_option = args.theme_option
super(ShellPowerline, self).__init__(args.ext[0], args.renderer_module, **kwargs)
def load_main_config(self):
r = super(ShellPowerline, self).load_main_config()
if self.args.config:
mergedicts(r, mergeargs(self.args.config))
mergedicts(r, self.args.config)
return r
def load_theme_config(self, name):
@ -49,7 +50,17 @@ def get_argparser(parser=None, *args, **kwargs):
p.add_argument('-w', '--width', type=int)
p.add_argument('--last_exit_code', metavar='INT', type=int)
p.add_argument('--last_pipe_status', metavar='LIST', default='', type=lambda s: [int(status) for status in s.split()])
p.add_argument('-c', '--config', metavar='KEY.KEY=VALUE', type=parsedotval, action='append')
p.add_argument('-t', '--theme_option', metavar='THEME.KEY.KEY=VALUE', type=parsedotval, action='append')
p.add_argument('-c', '--config', metavar='KEY.KEY=VALUE', action='append')
p.add_argument('-t', '--theme_option', metavar='THEME.KEY.KEY=VALUE', action='append')
p.add_argument('-p', '--config_path', metavar='PATH')
p.add_argument('-R', '--renderer_arg', metavar='KEY="VAL"', type=lambda a: dict([parsedotval(a)]))
return p
def finish_args(args):
if args.config:
args.config = mergeargs((parsedotval(v) for v in args.config))
if args.theme_option:
args.theme_option = mergeargs((parsedotval(v) for v in args.config))
else:
args.theme_option = {}

View File

@ -5,19 +5,23 @@ import sys
import os
try:
from powerline.shell import ShellPowerline, get_argparser
from powerline.shell import ShellPowerline, get_argparser, finish_args
except ImportError:
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from powerline.shell import ShellPowerline, get_argparser # NOQA
from powerline.shell import ShellPowerline, get_argparser, finish_args # NOQA
if __name__ == '__main__':
args = get_argparser(description=__doc__).parse_args()
finish_args(args)
powerline = ShellPowerline(args, run_once=True)
segment_info = {'args': args, 'environ': os.environ},
if args.renderer_arg:
segment_info.update(args.renderer_arg)
rendered = powerline.render(
width=args.width,
side=args.side,
segment_info={'args': args, 'environ': os.environ},
segment_info=segment_info,
)
try:
sys.stdout.write(rendered)

View File

@ -17,7 +17,7 @@ class Pl(object):
class Args(object):
theme_option = None
theme_option = {}
config = None
config_path = None
ext = ['shell']

View File

@ -71,7 +71,7 @@ class TestConfig(TestCase):
def test_bash(self):
from powerline.shell import ShellPowerline
args = Args(last_exit_code=1, ext=['shell'], renderer_module='bash_prompt', config=[('ext', {'shell': {'theme': 'default_leftonly'}})])
args = Args(last_exit_code=1, ext=['shell'], renderer_module='bash_prompt', config={'ext': {'shell': {'theme': 'default_leftonly'}}})
with ShellPowerline(args, run_once=False) as powerline:
powerline.render(segment_info={'args': args})
with ShellPowerline(args, run_once=False) as powerline: