mirror of
https://github.com/powerline/powerline.git
synced 2025-07-31 01:35:40 +02:00
Use direct execution by default
Should make it not needed to bother with environment variables. Makes tmux configuration more fragile. Is a different variant of fixing #1354. Does not conflict with the previous one, so both are kept.
This commit is contained in:
parent
9f7e59d0cf
commit
bd9359c983
@ -5,13 +5,15 @@ import os
|
|||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import shlex
|
||||||
|
|
||||||
from powerline.config import POWERLINE_ROOT, TMUX_CONFIG_DIRECTORY
|
from powerline.config import POWERLINE_ROOT, TMUX_CONFIG_DIRECTORY
|
||||||
from powerline.lib.config import ConfigLoader
|
from powerline.lib.config import ConfigLoader
|
||||||
from powerline import generate_config_finder, load_config, create_logger, PowerlineLogger, finish_common_config
|
from powerline import generate_config_finder, load_config, create_logger, PowerlineLogger, finish_common_config
|
||||||
from powerline.shell import ShellPowerline
|
from powerline.shell import ShellPowerline
|
||||||
from powerline.lib.shell import which
|
from powerline.lib.shell import which
|
||||||
from powerline.bindings.tmux import TmuxVersionInfo, run_tmux_command, set_tmux_environment, get_tmux_version
|
from powerline.bindings.tmux import (TmuxVersionInfo, run_tmux_command, set_tmux_environment, get_tmux_version,
|
||||||
|
source_tmux_file)
|
||||||
from powerline.lib.encoding import get_preferred_output_encoding
|
from powerline.lib.encoding import get_preferred_output_encoding
|
||||||
from powerline.renderers.tmux import attrs_to_tmux_attrs
|
from powerline.renderers.tmux import attrs_to_tmux_attrs
|
||||||
from powerline.commands.main import finish_args
|
from powerline.commands.main import finish_args
|
||||||
@ -60,7 +62,7 @@ def get_tmux_configs(version):
|
|||||||
yield (fname, priority + file_version.minor * 10 + file_version.major * 10000)
|
yield (fname, priority + file_version.minor * 10 + file_version.major * 10000)
|
||||||
|
|
||||||
|
|
||||||
def source_tmux_files(pl, args):
|
def source_tmux_files(pl, args, source_tmux_file=source_tmux_file):
|
||||||
'''Source relevant version-specific tmux configuration files
|
'''Source relevant version-specific tmux configuration files
|
||||||
|
|
||||||
Files are sourced in the following order:
|
Files are sourced in the following order:
|
||||||
@ -69,9 +71,9 @@ def source_tmux_files(pl, args):
|
|||||||
sourced, then _plus files and then files without _minus or _plus suffixes.
|
sourced, then _plus files and then files without _minus or _plus suffixes.
|
||||||
'''
|
'''
|
||||||
version = get_tmux_version(pl)
|
version = get_tmux_version(pl)
|
||||||
run_tmux_command('source', os.path.join(TMUX_CONFIG_DIRECTORY, 'powerline-base.conf'))
|
source_tmux_file(os.path.join(TMUX_CONFIG_DIRECTORY, 'powerline-base.conf'))
|
||||||
for fname, priority in sorted(get_tmux_configs(version), key=(lambda v: v[1])):
|
for fname, priority in sorted(get_tmux_configs(version), key=(lambda v: v[1])):
|
||||||
run_tmux_command('source', fname)
|
source_tmux_file(fname)
|
||||||
if not os.environ.get('POWERLINE_COMMAND'):
|
if not os.environ.get('POWERLINE_COMMAND'):
|
||||||
cmd = deduce_command()
|
cmd = deduce_command()
|
||||||
if cmd:
|
if cmd:
|
||||||
@ -93,7 +95,7 @@ class EmptyArgs(object):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def init_tmux_environment(pl, args):
|
def init_tmux_environment(pl, args, set_tmux_environment=set_tmux_environment):
|
||||||
'''Initialize tmux environment from tmux configuration
|
'''Initialize tmux environment from tmux configuration
|
||||||
'''
|
'''
|
||||||
powerline = ShellPowerline(finish_args(os.environ, EmptyArgs('tmux', args.config_path)))
|
powerline = ShellPowerline(finish_args(os.environ, EmptyArgs('tmux', args.config_path)))
|
||||||
@ -175,6 +177,35 @@ def tmux_setup(pl, args):
|
|||||||
source_tmux_files(pl, args)
|
source_tmux_files(pl, args)
|
||||||
|
|
||||||
|
|
||||||
|
TMUX_VAR_RE = re.compile('\$(_POWERLINE_\w+)')
|
||||||
|
|
||||||
|
|
||||||
|
def tmux_setup_nosource(pl, args):
|
||||||
|
tmux_environ = {}
|
||||||
|
|
||||||
|
def set_tmux_environment(varname, value, remove=True):
|
||||||
|
tmux_environ[varname] = value
|
||||||
|
|
||||||
|
init_tmux_environment(pl, args, set_tmux_environment=set_tmux_environment)
|
||||||
|
|
||||||
|
def replace_cb(match):
|
||||||
|
return tmux_environ[match.group(1)]
|
||||||
|
|
||||||
|
def replace_env(s):
|
||||||
|
return TMUX_VAR_RE.subn(replace_cb, s)[0]
|
||||||
|
|
||||||
|
def source_tmux_file(fname):
|
||||||
|
with open(fname) as fd:
|
||||||
|
for line in fd:
|
||||||
|
if line.startswith('#') or line == '\n':
|
||||||
|
continue
|
||||||
|
args = shlex.split(line)
|
||||||
|
args = [args[0]] + [replace_env(arg) for arg in args[1:]]
|
||||||
|
run_tmux_command(*args)
|
||||||
|
|
||||||
|
source_tmux_files(pl, args, source_tmux_file=source_tmux_file)
|
||||||
|
|
||||||
|
|
||||||
def get_main_config(args):
|
def get_main_config(args):
|
||||||
find_config_files = generate_config_finder()
|
find_config_files = generate_config_finder()
|
||||||
config_loader = ConfigLoader(run_once=True)
|
config_loader = ConfigLoader(run_once=True)
|
||||||
|
@ -58,6 +58,15 @@ def set_tmux_environment(varname, value, remove=True):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def source_tmux_file(fname):
|
||||||
|
'''Source tmux configuration file
|
||||||
|
|
||||||
|
:param str fname:
|
||||||
|
Full path to the sourced file.
|
||||||
|
'''
|
||||||
|
run_tmux_command('source', fname)
|
||||||
|
|
||||||
|
|
||||||
NON_DIGITS = re.compile('[^0-9]+')
|
NON_DIGITS = re.compile('[^0-9]+')
|
||||||
DIGITS = re.compile('[0-9]+')
|
DIGITS = re.compile('[0-9]+')
|
||||||
NON_LETTERS = re.compile('[^a-z]+')
|
NON_LETTERS = re.compile('[^a-z]+')
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
if-shell 'env "$POWERLINE_CONFIG_COMMAND" tmux setup' '' 'run-shell "powerline-config tmux setup"'
|
if-shell 'env "$POWERLINE_CONFIG_COMMAND" tmux setup-nosource' '' 'run-shell "powerline-config tmux setup-nosource"'
|
||||||
# vim: ft=tmux
|
# vim: ft=tmux
|
||||||
|
@ -22,6 +22,7 @@ TMUX_ACTIONS = {
|
|||||||
'source': StrFunction(config.source_tmux_files, 'source'),
|
'source': StrFunction(config.source_tmux_files, 'source'),
|
||||||
'setenv': StrFunction(config.init_tmux_environment, 'setenv'),
|
'setenv': StrFunction(config.init_tmux_environment, 'setenv'),
|
||||||
'setup': StrFunction(config.tmux_setup, 'setup'),
|
'setup': StrFunction(config.tmux_setup, 'setup'),
|
||||||
|
'setup-nosource': StrFunction(config.tmux_setup_nosource, 'setup-nosource'),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user