diff --git a/powerline/bindings/bash/powerline.sh b/powerline/bindings/bash/powerline.sh index 50eb4878..ba33e2aa 100644 --- a/powerline/bindings/bash/powerline.sh +++ b/powerline/bindings/bash/powerline.sh @@ -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 diff --git a/powerline/bindings/tmux/powerline.conf b/powerline/bindings/tmux/powerline.conf index 5d43cd37..5951848c 100644 --- a/powerline/bindings/tmux/powerline.conf +++ b/powerline/bindings/tmux/powerline.conf @@ -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]" diff --git a/powerline/bindings/zsh/powerline.zsh b/powerline/bindings/zsh/powerline.zsh index a45a6657..301bc411 100644 --- a/powerline/bindings/zsh/powerline.zsh +++ b/powerline/bindings/zsh/powerline.zsh @@ -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 } diff --git a/powerline/lib/__init__.py b/powerline/lib/__init__.py index 8f6a7ba2..f8d831ac 100644 --- a/powerline/lib/__init__.py +++ b/powerline/lib/__init__.py @@ -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) diff --git a/powerline/renderers/tmux.py b/powerline/renderers/tmux.py index 34e4329e..19ac3fed 100644 --- a/powerline/renderers/tmux.py +++ b/powerline/renderers/tmux.py @@ -40,5 +40,17 @@ 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: + print r['pane_id'] + print sorted(r['environ'].keys()) + varname = 'TMUX_PWD_' + r['pane_id'].lstrip('%') + if varname in r['environ']: + r['getcwd'] = lambda: r['environ'][varname] + return r + renderer = TmuxRenderer diff --git a/powerline/shell.py b/powerline/shell.py index 2ff2c9e4..8b9e8045 100644 --- a/powerline/shell.py +++ b/powerline/shell.py @@ -53,6 +53,7 @@ def get_argparser(parser=None, *args, **kwargs): 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 diff --git a/scripts/powerline b/scripts/powerline index c4e8b0aa..264f1794 100755 --- a/scripts/powerline +++ b/scripts/powerline @@ -15,10 +15,13 @@ 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)