def source_tmux_files(pl, args, tmux_version=None, source_tmux_file=source_tmux_file): '''Source relevant version-specific tmux configuration files Files are sourced in the following order: * First relevant files with older versions are sourced. * If files for same versions are to be sourced then first _minus files are sourced, then _plus files and then files without _minus or _plus suffixes. ''' tmux_version = tmux_version or get_tmux_version(pl) source_tmux_file(os.path.join(TMUX_CONFIG_DIRECTORY, 'powerline-base.conf')) for fname, priority in sorted(get_tmux_configs(tmux_version), key=(lambda v: v[1])): source_tmux_file(fname) if not os.environ.get('POWERLINE_COMMAND'): cmd = deduce_command() if cmd: set_tmux_environment('POWERLINE_COMMAND', deduce_command(), remove=False) try: run_tmux_command('refresh-client') except subprocess.CalledProcessError: # On tmux-2.0 this command may fail for whatever reason. Since it is # critical just ignore the failure. pass
def source_tmux_files(pl, args): '''Source relevant version-specific tmux configuration files Files are sourced in the following order: * First relevant files with older versions are sourced. * If files for same versions are to be sourced then first _minus files are sourced, then _plus files and then files without _minus or _plus suffixes. ''' version = get_tmux_version(pl) run_tmux_command('source', os.path.join(TMUX_CONFIG_DIRECTORY, 'powerline-base.conf')) for fname, priority in sorted(get_tmux_configs(version), key=(lambda v: v[1])): run_tmux_command('source', fname) if not os.environ.get('POWERLINE_COMMAND'): cmd = deduce_command() if cmd: set_tmux_environment('POWERLINE_COMMAND', deduce_command(), remove=False) run_tmux_command('refresh-client')
def init_environment(pl, args): '''Initialize tmux environment from tmux configuration ''' powerline = TmuxPowerline(args.config_path) # TODO Move configuration files loading out of Powerline object and use it # directly powerline.update_renderer() # FIXME Use something more stable then `theme_kwargs` colorscheme = powerline.renderer_options['theme_kwargs']['colorscheme'] def get_highlighting(group): return colorscheme.get_highlighting([group], None) for varname, highlight_group in ( ('_POWERLINE_BACKGROUND_COLOR', 'background'), ('_POWERLINE_ACTIVE_WINDOW_STATUS_COLOR', 'active_window_status'), ('_POWERLINE_WINDOW_STATUS_COLOR', 'window_status'), ('_POWERLINE_ACTIVITY_STATUS_COLOR', 'activity_status'), ('_POWERLINE_BELL_STATUS_COLOR', 'bell_status'), ('_POWERLINE_WINDOW_COLOR', 'window'), ('_POWERLINE_WINDOW_DIVIDER_COLOR', 'window:divider'), ('_POWERLINE_WINDOW_CURRENT_COLOR', 'window:current'), ('_POWERLINE_WINDOW_NAME_COLOR', 'window_name'), ('_POWERLINE_SESSION_COLOR', 'session'), ): highlight = get_highlighting(highlight_group) set_tmux_environment(varname, powerline.renderer.hlstyle(**highlight)[2:-1]) for varname, prev_group, next_group in ( ('_POWERLINE_WINDOW_CURRENT_HARD_DIVIDER_COLOR', 'window', 'window:current'), ('_POWERLINE_WINDOW_CURRENT_HARD_DIVIDER_NEXT_COLOR', 'window:current', 'window'), ('_POWERLINE_SESSION_HARD_DIVIDER_NEXT_COLOR', 'session', 'background'), ): prev_highlight = get_highlighting(prev_group) next_highlight = get_highlighting(next_group) set_tmux_environment( varname, powerline.renderer.hlstyle( fg=prev_highlight['bg'], bg=next_highlight['bg'], attr=0, )[2:-1] ) for varname, attr, group in ( ('_POWERLINE_ACTIVE_WINDOW_FG', 'fg', 'active_window_status'), ('_POWERLINE_WINDOW_STATUS_FG', 'fg', 'window_status'), ('_POWERLINE_ACTIVITY_STATUS_FG', 'fg', 'activity_status'), ('_POWERLINE_ACTIVITY_STATUS_ATTR', 'attr', 'activity_status'), ('_POWERLINE_BELL_STATUS_FG', 'fg', 'bell_status'), ('_POWERLINE_BELL_STATUS_ATTR', 'attr', 'bell_status'), ('_POWERLINE_BACKGROUND_FG', 'fg', 'background'), ('_POWERLINE_BACKGROUND_BG', 'bg', 'background'), ('_POWERLINE_SESSION_FG', 'fg', 'session'), ('_POWERLINE_SESSION_BG', 'bg', 'session'), ('_POWERLINE_SESSION_ATTR', 'attr', 'session'), ('_POWERLINE_SESSION_PREFIX_FG', 'fg', 'session:prefix'), ('_POWERLINE_SESSION_PREFIX_BG', 'bg', 'session:prefix'), ('_POWERLINE_SESSION_PREFIX_ATTR', 'attr', 'session:prefix'), ): if attr == 'attr': attrs = attr_to_tmux_attr(get_highlighting(group)[attr]) set_tmux_environment(varname, ']#['.join(attrs)) set_tmux_environment(varname + '_LEGACY', ','.join(attrs)) else: set_tmux_environment(varname, 'colour' + str(get_highlighting(group)[attr][0])) left_dividers = powerline.renderer.theme.dividers['left'] set_tmux_environment('_POWERLINE_LEFT_HARD_DIVIDER', left_dividers['hard']) set_tmux_environment('_POWERLINE_LEFT_SOFT_DIVIDER', left_dividers['soft']) set_tmux_environment('_POWERLINE_LEFT_HARD_DIVIDER_SPACES', ( ' ' * powerline.renderer.strwidth(left_dividers['hard'])))
def init_tmux_environment(pl, args, set_tmux_environment=set_tmux_environment): '''Initialize tmux environment from tmux configuration ''' powerline = ShellPowerline( finish_args(None, os.environ, EmptyArgs('tmux', args.config_path))) # TODO Move configuration files loading out of Powerline object and use it # directly powerline.update_renderer() # FIXME Use something more stable then `theme_kwargs` colorscheme = powerline.renderer_options['theme_kwargs']['colorscheme'] def get_highlighting(group): return colorscheme.get_highlighting([group], None) for varname, highlight_group in ( ('_POWERLINE_BACKGROUND_COLOR', 'background'), ('_POWERLINE_ACTIVE_WINDOW_STATUS_COLOR', 'active_window_status'), ('_POWERLINE_WINDOW_STATUS_COLOR', 'window_status'), ('_POWERLINE_ACTIVITY_STATUS_COLOR', 'activity_status'), ('_POWERLINE_BELL_STATUS_COLOR', 'bell_status'), ('_POWERLINE_WINDOW_COLOR', 'window'), ('_POWERLINE_WINDOW_DIVIDER_COLOR', 'window:divider'), ('_POWERLINE_WINDOW_CURRENT_COLOR', 'window:current'), ('_POWERLINE_WINDOW_NAME_COLOR', 'window_name'), ('_POWERLINE_SESSION_COLOR', 'session'), ): highlight = get_highlighting(highlight_group) set_tmux_environment(varname, powerline.renderer.hlstyle(**highlight)[2:-1]) for varname, prev_group, next_group in ( ('_POWERLINE_WINDOW_CURRENT_HARD_DIVIDER_COLOR', 'window', 'window:current'), ('_POWERLINE_WINDOW_CURRENT_HARD_DIVIDER_NEXT_COLOR', 'window:current', 'window'), ('_POWERLINE_SESSION_HARD_DIVIDER_NEXT_COLOR', 'session', 'background'), ): prev_highlight = get_highlighting(prev_group) next_highlight = get_highlighting(next_group) set_tmux_environment( varname, powerline.renderer.hlstyle( fg=prev_highlight['bg'], bg=next_highlight['bg'], attrs=0, )[2:-1]) for varname, attr, group in ( ('_POWERLINE_ACTIVE_WINDOW_FG', 'fg', 'active_window_status'), ('_POWERLINE_WINDOW_STATUS_FG', 'fg', 'window_status'), ('_POWERLINE_ACTIVITY_STATUS_FG', 'fg', 'activity_status'), ('_POWERLINE_ACTIVITY_STATUS_ATTR', 'attrs', 'activity_status'), ('_POWERLINE_BELL_STATUS_FG', 'fg', 'bell_status'), ('_POWERLINE_BELL_STATUS_ATTR', 'attrs', 'bell_status'), ('_POWERLINE_BACKGROUND_FG', 'fg', 'background'), ('_POWERLINE_BACKGROUND_BG', 'bg', 'background'), ('_POWERLINE_SESSION_FG', 'fg', 'session'), ('_POWERLINE_SESSION_BG', 'bg', 'session'), ('_POWERLINE_SESSION_ATTR', 'attrs', 'session'), ('_POWERLINE_SESSION_PREFIX_FG', 'fg', 'session:prefix'), ('_POWERLINE_SESSION_PREFIX_BG', 'bg', 'session:prefix'), ('_POWERLINE_SESSION_PREFIX_ATTR', 'attrs', 'session:prefix'), ): if attr == 'attrs': attrs = attrs_to_tmux_attrs(get_highlighting(group)[attr]) set_tmux_environment(varname, ']#['.join(attrs)) set_tmux_environment( varname + '_LEGACY', ( ','.join( # Tmux-1.6 does not accept no… attributes in # window-status-…-attr options. (attr for attr in attrs if not attr.startswith('no'))) # But it does not support empty attributes as well. or 'none')) else: if powerline.common_config['term_truecolor']: set_tmux_environment( varname, '#{0:06x}'.format(get_highlighting(group)[attr][1])) else: set_tmux_environment( varname, 'colour' + str(get_highlighting(group)[attr][0])) left_dividers = powerline.renderer.theme.dividers['left'] set_tmux_environment('_POWERLINE_LEFT_HARD_DIVIDER', left_dividers['hard']) set_tmux_environment('_POWERLINE_LEFT_SOFT_DIVIDER', left_dividers['soft']) set_tmux_environment( '_POWERLINE_LEFT_HARD_DIVIDER_SPACES', (' ' * powerline.renderer.strwidth(left_dividers['hard'])))
def init_tmux_environment(pl, args, set_tmux_environment=set_tmux_environment): '''Initialize tmux environment from tmux configuration ''' powerline = ShellPowerline(finish_args(None, os.environ, EmptyArgs('tmux', args.config_path))) # TODO Move configuration files loading out of Powerline object and use it # directly powerline.update_renderer() # FIXME Use something more stable then `theme_kwargs` colorscheme = powerline.renderer_options['theme_kwargs']['colorscheme'] def get_highlighting(group): return colorscheme.get_highlighting([group], None) for varname, highlight_group in ( ('_POWERLINE_BACKGROUND_COLOR', 'background'), ('_POWERLINE_ACTIVE_WINDOW_STATUS_COLOR', 'active_window_status'), ('_POWERLINE_WINDOW_STATUS_COLOR', 'window_status'), ('_POWERLINE_ACTIVITY_STATUS_COLOR', 'activity_status'), ('_POWERLINE_BELL_STATUS_COLOR', 'bell_status'), ('_POWERLINE_WINDOW_COLOR', 'window'), ('_POWERLINE_WINDOW_DIVIDER_COLOR', 'window:divider'), ('_POWERLINE_WINDOW_CURRENT_COLOR', 'window:current'), ('_POWERLINE_WINDOW_NAME_COLOR', 'window_name'), ('_POWERLINE_SESSION_COLOR', 'session'), ): highlight = get_highlighting(highlight_group) set_tmux_environment(varname, powerline.renderer.hlstyle(**highlight)[2:-1]) for varname, prev_group, next_group in ( ('_POWERLINE_WINDOW_CURRENT_HARD_DIVIDER_COLOR', 'window', 'window:current'), ('_POWERLINE_WINDOW_CURRENT_HARD_DIVIDER_NEXT_COLOR', 'window:current', 'window'), ('_POWERLINE_SESSION_HARD_DIVIDER_NEXT_COLOR', 'session', 'background'), ): prev_highlight = get_highlighting(prev_group) next_highlight = get_highlighting(next_group) set_tmux_environment( varname, powerline.renderer.hlstyle( fg=prev_highlight['bg'], bg=next_highlight['bg'], attrs=0, )[2:-1] ) for varname, attr, group in ( ('_POWERLINE_ACTIVE_WINDOW_FG', 'fg', 'active_window_status'), ('_POWERLINE_WINDOW_STATUS_FG', 'fg', 'window_status'), ('_POWERLINE_ACTIVITY_STATUS_FG', 'fg', 'activity_status'), ('_POWERLINE_ACTIVITY_STATUS_ATTR', 'attrs', 'activity_status'), ('_POWERLINE_BELL_STATUS_FG', 'fg', 'bell_status'), ('_POWERLINE_BELL_STATUS_ATTR', 'attrs', 'bell_status'), ('_POWERLINE_BACKGROUND_FG', 'fg', 'background'), ('_POWERLINE_BACKGROUND_BG', 'bg', 'background'), ('_POWERLINE_SESSION_FG', 'fg', 'session'), ('_POWERLINE_SESSION_BG', 'bg', 'session'), ('_POWERLINE_SESSION_ATTR', 'attrs', 'session'), ('_POWERLINE_SESSION_PREFIX_FG', 'fg', 'session:prefix'), ('_POWERLINE_SESSION_PREFIX_BG', 'bg', 'session:prefix'), ('_POWERLINE_SESSION_PREFIX_ATTR', 'attrs', 'session:prefix'), ): if attr == 'attrs': attrs = attrs_to_tmux_attrs(get_highlighting(group)[attr]) set_tmux_environment(varname, ']#['.join(attrs)) set_tmux_environment(varname + '_LEGACY', (','.join( # Tmux-1.6 does not accept no… attributes in # window-status-…-attr options. (attr for attr in attrs if not attr.startswith('no'))) # But it does not support empty attributes as well. or 'none')) else: if powerline.common_config['term_truecolor']: set_tmux_environment(varname, '#{0:06x}'.format(get_highlighting(group)[attr][1])) else: set_tmux_environment(varname, 'colour' + str(get_highlighting(group)[attr][0])) left_dividers = powerline.renderer.theme.dividers['left'] set_tmux_environment('_POWERLINE_LEFT_HARD_DIVIDER', left_dividers['hard']) set_tmux_environment('_POWERLINE_LEFT_SOFT_DIVIDER', left_dividers['soft']) set_tmux_environment('_POWERLINE_LEFT_HARD_DIVIDER_SPACES', ( ' ' * powerline.renderer.strwidth(left_dividers['hard'])))