diff --git a/docs/source/develop/segments.rst b/docs/source/develop/segments.rst index 8d752229..d96bb1cb 100644 --- a/docs/source/develop/segments.rst +++ b/docs/source/develop/segments.rst @@ -467,7 +467,8 @@ Shell ``client_id`` Identifier unique to one shell instance. Is used to record instance - state by powerline daemon. + state by powerline daemon. In tmux this is the same as :ref:`pane_id + `. It is not guaranteed that existing client ID will not be retaken when old shell with this ID quit: usually process PID is used as @@ -481,6 +482,14 @@ Shell Local theme that will be used by shell. One should not rely on the existence of this key. + .. _dev-seginfo-shell-renarg-pane_id: + + ``pane_id`` + Identifier unique to each tmux pane. Is always an integer, optional. + Obtained by using ``tmux display -p '#D'``, then all leading spaces + and per cent signs are stripped and the result is converted into an + integer. + Other keys, if any, are specific to segments. Ipython diff --git a/powerline/commands/main.py b/powerline/commands/main.py index da228edf..a5b27ef7 100644 --- a/powerline/commands/main.py +++ b/powerline/commands/main.py @@ -10,7 +10,7 @@ from itertools import chain from powerline.lib.overrides import parsedotval, parse_override_var from powerline.lib.dict import mergeargs from powerline.lib.encoding import get_preferred_arguments_encoding -from powerline.lib.unicode import u +from powerline.lib.unicode import u, unicode if sys.version_info < (3,): @@ -49,6 +49,14 @@ def finish_args(environ, args): )) if args.renderer_arg: args.renderer_arg = mergeargs((parsedotval(v) for v in args.renderer_arg), remove=True) + if 'pane_id' in args.renderer_arg: + if isinstance(args.renderer_arg['pane_id'], (bytes, unicode)): + try: + args.renderer_arg['pane_id'] = int(args.renderer_arg['pane_id'].lstrip(' %')) + except ValueError: + pass + if 'client_id' not in args.renderer_arg: + args.renderer_arg['client_id'] = args.renderer_arg['pane_id'] args.config_path = ( [path for path in environ.get('POWERLINE_CONFIG_PATHS', '').split(':') if path] + (args.config_path or []) diff --git a/powerline/renderers/tmux.py b/powerline/renderers/tmux.py index 33556409..840bbdda 100644 --- a/powerline/renderers/tmux.py +++ b/powerline/renderers/tmux.py @@ -63,7 +63,7 @@ class TmuxRenderer(Renderer): if segment_info: r.update(segment_info) if 'pane_id' in r: - varname = 'TMUX_PWD_' + r['pane_id'].lstrip('% ') + varname = 'TMUX_PWD_' + str(r['pane_id']) if varname in r['environ']: r['getcwd'] = lambda: r['environ'][varname] r['mode'] = mode