Merge pull request #973 from ZyX-I/ext-components

Add components configuration option
This commit is contained in:
Nikolai Aleksandrovich Pavlov 2014-08-10 16:44:09 +04:00
commit 60c9f8b526
26 changed files with 307 additions and 125 deletions

View File

@ -106,8 +106,10 @@ int main(int argc, char *argv[]) {
wd = getcwd(NULL, 0); wd = getcwd(NULL, 0);
if (wd != NULL) { if (wd != NULL) {
do_write(sd, wd, strlen(wd)); do_write(sd, wd, strlen(wd));
free(wd); wd = NULL; free(wd);
wd = NULL;
} }
do_write(sd, eof, 1);
for(envp=environ; *envp; envp++) { for(envp=environ; *envp; envp++) {
do_write(sd, *envp, strlen(*envp)); do_write(sd, *envp, strlen(*envp));

View File

@ -81,12 +81,13 @@ are taken from zsh variables.
but only subdictionaries for ``THEME_NAME`` key are merged with theme but only subdictionaries for ``THEME_NAME`` key are merged with theme
configuration when theme with given name is requested. configuration when theme with given name is requested.
``POWERLINE_CONFIG_PATH`` ``POWERLINE_CONFIG_PATHS``
Sets directory where configuration should be read from. If present, no Sets directories where configuration should be read from. If present, no
default locations are searched for configuration. No expansions are default locations are searched for configuration. No expansions are
performed by powerline script itself, but zsh usually performs them on its performed by powerline script itself, but zsh usually performs them on its
own if you set variable without quotes: ``POWERLINE_CONFIG_PATH=~/example``. own if you set variable without quotes: ``POWERLINE_CONFIG_PATHS=( ~/example
Expansion depends on zsh configuration. )``. You should use array parameter or the usual colon-separated
``POWERLINE_CONFIG_PATHS=$HOME/path1:$HOME/path2``.
Ipython overrides Ipython overrides
================= =================
@ -104,8 +105,8 @@ use ``c.Powerline.KEY``. Supported ``KEY`` strings or keyword argument names:
a dictionary where keys are theme names and values are dictionaries which a dictionary where keys are theme names and values are dictionaries which
will be recursively merged with the contents of the given theme. will be recursively merged with the contents of the given theme.
``path`` ``paths``
Sets directory where configuration should be read from. If present, no Sets directories where configuration should be read from. If present, no
default locations are searched for configuration. No expansions are default locations are searched for configuration. No expansions are
performed thus you cannot use paths starting with ``~/``. performed thus you cannot use paths starting with ``~/``.
@ -114,9 +115,9 @@ Prompt command
In addition to the above configuration options you can use In addition to the above configuration options you can use
``$POWERLINE_COMMAND`` environment variable to tell shell or tmux to use ``$POWERLINE_COMMAND`` environment variable to tell shell or tmux to use
specific powerline implementation. This is mostly useful for putting powerline specific powerline implementation and ``$POWERLINE_CONFIG`` to tell zsh or tmux
into different directory or replacing ``powerline`` script with where ``powerline-config`` script is located. This is mostly useful for putting
``powerline-client`` for performance reasons. powerline into different directory.
.. note:: .. note::
@ -149,6 +150,6 @@ fish in order to support multiline prompt you should set
.. note:: .. note::
Most supported shells configuration scripts check for additional Most supported shells configuration scripts check for ``$POWERLINE_CONFIG``
configuration variables being empty. But tcsh configuration script checks and ``$POWERLINE_COMMAND`` configuration variables being empty. But tcsh
for variables being *defined*, not empty. configuration script checks for variables being *defined*, not empty.

View File

@ -101,20 +101,20 @@ Common configuration is a subdictionary that is a value of ``ext`` key in
``colorscheme`` ``colorscheme``
Defines the colorscheme used for this extension. Defines the colorscheme used for this extension.
``theme`` .. _config-ext-theme:
.. _config-ext-theme:
``theme``
Defines the theme used for this extension. Defines the theme used for this extension.
``top_theme`` .. _config-ext-top_theme:
.. _config-ext-top_theme:
``top_theme``
Defines the top-level theme used for this extension. See `Themes`_ section Defines the top-level theme used for this extension. See `Themes`_ section
for more details. for more details.
``local_themes`` .. _config-ext-local_themes:
.. _config-ext-local_themes:
``local_themes``
Defines themes used when certain conditions are met, e.g. for Defines themes used when certain conditions are met, e.g. for
buffer-specific statuslines in vim. Value depends on extension used. For vim buffer-specific statuslines in vim. Value depends on extension used. For vim
it is a dictionary ``{matcher_name : theme_name}``, where ``matcher_name`` it is a dictionary ``{matcher_name : theme_name}``, where ``matcher_name``
@ -123,6 +123,28 @@ Common configuration is a subdictionary that is a value of ``ext`` key in
``module_attribute`` should point to a function that returns boolean value ``module_attribute`` should point to a function that returns boolean value
indicating that current buffer has (not) matched conditions. indicating that current buffer has (not) matched conditions.
``components``
Determines which extension components should be enabled. This key is highly
extension-specific, here is the table of extensions and corresponding
components:
+---------+----------+-----------------------------------------------------+
|Extension|Component |Description |
+---------+----------+-----------------------------------------------------+
|vim |statusline|Makes Vim use powerline statusline. |
| +----------+-----------------------------------------------------+
| |tabline |Makes Vim use powerline tabline. |
+---------+----------+-----------------------------------------------------+
|shell |prompt |Makes shell display powerline prompt. |
| +----------+-----------------------------------------------------+
| |tmux |Makes shell report its current working directory |
| | |and screen width to tmux for tmux powerline |
| | |bindings. |
| | |  |
+---------+----------+-----------------------------------------------------+
All components are enabled by default.
.. _config-colors: .. _config-colors:
Color definitions Color definitions
@ -324,54 +346,54 @@ ascii Theme without any unicode characters at all
<config-themes-seg-segments>` and :ref:`args <config-themes-seg-segments>` and :ref:`args
<config-themes-seg-args>` options. <config-themes-seg-args>` options.
``module``
.. _config-themes-seg-module: .. _config-themes-seg-module:
``module``
Function module, only required for function segments. Defaults to Function module, only required for function segments. Defaults to
``powerline.segments.{extension}``. Default is overriden by ``powerline.segments.{extension}``. Default is overriden by
:ref:`default_module theme option <config-themes-default_module>`. :ref:`default_module theme option <config-themes-default_module>`.
``name``
.. _config-themes-seg-name: .. _config-themes-seg-name:
``name``
Function name, only required for function and list segments. Function name, only required for function and list segments.
``highlight_group``
.. _config-themes-seg-highlight_group: .. _config-themes-seg-highlight_group:
Highlighting group for this segment. Consists of a prioritized list ``highlight_group``
of highlighting groups, where the first highlighting group that is Highlighting group for this segment. Consists of a prioritized list of
highlighting groups, where the first highlighting group that is
available in the colorscheme is used. available in the colorscheme is used.
Ignored for segments that have ``function`` type. Ignored for segments that have ``function`` type.
``before``
.. _config-themes-seg-before: .. _config-themes-seg-before:
``before``
A string which will be prepended to the segment contents. A string which will be prepended to the segment contents.
``after``
.. _config-themes-seg-after: .. _config-themes-seg-after:
``after``
A string which will be appended to the segment contents. A string which will be appended to the segment contents.
``contents``
.. _config-themes-seg-contents: .. _config-themes-seg-contents:
``contents``
Segment contents, only required for ``string`` segments. Segment contents, only required for ``string`` segments.
``args``
.. _config-themes-seg-args: .. _config-themes-seg-args:
``args``
A dict of arguments to be passed to a ``function`` segment. A dict of arguments to be passed to a ``function`` segment.
``align`` ``align``
Aligns the segments contents to the left (``l``), center (``c``) or Aligns the segments contents to the left (``l``), center (``c``) or
right (``r``). right (``r``).
``width``
.. _config-themes-seg-width: .. _config-themes-seg-width:
``width``
Enforces a specific width for this segment. Enforces a specific width for this segment.
This segment will work as a spacer if the width is set to ``auto``. This segment will work as a spacer if the width is set to ``auto``.
@ -412,13 +434,13 @@ ascii Theme without any unicode characters at all
A list of modes where this segment will be included: The segment is A list of modes where this segment will be included: The segment is
*not* included in any modes, *except* for the modes in this list. *not* included in any modes, *except* for the modes in this list.
``display``
.. _config-themes-seg-display: .. _config-themes-seg-display:
``display``
Boolean. If false disables displaying of the segment. Boolean. If false disables displaying of the segment.
Defaults to ``True``. Defaults to ``True``.
``segments``
.. _config-themes-seg-segments: .. _config-themes-seg-segments:
``segments``
A list of subsegments. A list of subsegments.

View File

@ -394,7 +394,15 @@ class Powerline(object):
self.ext_config = config['ext'][self.ext] self.ext_config = config['ext'][self.ext]
if self.ext_config != self.prev_ext_config: if self.ext_config != self.prev_ext_config:
ext_config_differs = True ext_config_differs = True
if not self.prev_ext_config or self.ext_config.get('local_themes') != self.prev_ext_config.get('local_themes'): if (
not self.prev_ext_config
or self.ext_config.get('components') != self.prev_ext_config.get('components')
):
self.setup_components(self.ext_config.get('components'))
if (
not self.prev_ext_config
or self.ext_config.get('local_themes') != self.prev_ext_config.get('local_themes')
):
self.renderer_options['local_themes'] = self.get_local_themes(self.ext_config.get('local_themes')) self.renderer_options['local_themes'] = self.get_local_themes(self.ext_config.get('local_themes'))
load_colorscheme = (load_colorscheme load_colorscheme = (load_colorscheme
or not self.prev_ext_config or not self.prev_ext_config
@ -439,6 +447,16 @@ class Powerline(object):
else: else:
self.renderer = renderer self.renderer = renderer
def setup_components(self, components):
'''Run component-specific setup
:param set components:
Set of the enabled componets or None.
Should be overridden by subclasses.
'''
pass
@staticmethod @staticmethod
def get_config_paths(): def get_config_paths():
'''Get configuration paths. '''Get configuration paths.

View File

@ -35,7 +35,7 @@ _powerline_init_tmux_support() {
_powerline_tmux_set_columns _powerline_tmux_set_columns
test "x$PROMPT_COMMAND" != "x${PROMPT_COMMAND/_powerline_tmux_set_pwd}" || test "x$PROMPT_COMMAND" != "x${PROMPT_COMMAND/_powerline_tmux_set_pwd}" ||
export PROMPT_COMMAND="${PROMPT_COMMAND}"$'\n_powerline_tmux_set_pwd' PROMPT_COMMAND="${PROMPT_COMMAND}"$'\n_powerline_tmux_set_pwd'
fi fi
} }
@ -54,21 +54,23 @@ _powerline_set_prompt() {
_powerline_setup_prompt() { _powerline_setup_prompt() {
VIRTUAL_ENV_DISABLE_PROMPT=1 VIRTUAL_ENV_DISABLE_PROMPT=1
if test -z "${POWERLINE_COMMAND}" ; then if test -z "${POWERLINE_COMMAND}" ; then
if which powerline-config &>/dev/null ; then POWERLINE_COMMAND="$("$POWERLINE_CONFIG" shell command)"
export POWERLINE_COMMAND="$(powerline-config shell command)"
else
# `$0` is set to `-bash` when using SSH so that won't work
local powerline_dir="$(dirname "$BASH_SOURCE")/../../.."
export POWERLINE_COMMAND="$($powerline_dir/scripts/powerline-config shell command)"
fi
fi fi
test "x$PROMPT_COMMAND" != "x${PROMPT_COMMAND%_powerline_set_prompt*}" || test "x$PROMPT_COMMAND" != "x${PROMPT_COMMAND%_powerline_set_prompt*}" ||
export PROMPT_COMMAND=$'_powerline_set_prompt\n'"${PROMPT_COMMAND}" PROMPT_COMMAND=$'_powerline_set_prompt\n'"${PROMPT_COMMAND}"
} }
if test -z "$POWERLINE_NO_BASH_PROMPT$POWERLINE_NO_SHELL_PROMPT" ; then if test -z "${POWERLINE_CONFIG}" ; then
if which powerline-config >/dev/null ; then
POWERLINE_CONFIG=powerline-config
else
POWERLINE_CONFIG="$(dirname "$BASH_SOURCE")/../../../scripts/powerline-config"
fi
fi
if "${POWERLINE_CONFIG}" shell --shell=bash uses prompt ; then
_powerline_setup_prompt _powerline_setup_prompt
fi fi
if test -z "$POWERLINE_NO_BASH_TMUX_SUPPORT$POWERLINE_NO_SHELL_TMUX_SUPPORT" ; then if "${POWERLINE_CONFIG}" shell --shell=bash uses tmux ; then
_powerline_init_tmux_support _powerline_init_tmux_support
fi fi

View File

@ -118,10 +118,14 @@ def source_tmux_files(pl, args):
run_tmux_command('refresh-client') run_tmux_command('refresh-client')
def create_powerline_logger(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)
config = load_config('config', find_config_files, config_loader) return load_config('config', find_config_files, config_loader)
def create_powerline_logger(args):
config = get_main_config(args)
common_config = finish_common_config(config['common']) common_config = finish_common_config(config['common'])
logger = create_logger(common_config) logger = create_logger(common_config)
return PowerlineLogger(use_daemon_threads=True, logger=logger, ext='config') return PowerlineLogger(use_daemon_threads=True, logger=logger, ext='config')
@ -166,3 +170,22 @@ def shell_command(pl, args):
print(cmd) print(cmd)
else: else:
sys.exit(1) sys.exit(1)
def uses(pl, args):
component = args.component
if not component:
raise ValueError('Must specify component')
shell = args.shell
template = 'POWERLINE_NO_{shell}_{component}'
for sh in (shell, 'shell') if shell else ('shell'):
varname = template.format(shell=sh.upper(), component=component.upper())
if os.environ.get(varname):
print ('HERE')
sys.exit(1)
config = get_main_config(args)
if component in config.get('ext', {}).get('shell', {}).get('components', ('tmux', 'prompt')):
sys.exit(0)
else:
print ('THERE')
sys.exit(1)

View File

@ -18,15 +18,18 @@ function powerline-setup
end end
end end
if test -z "$POWERLINE_NO_FISH_PROMPT$POWERLINE_NO_SHELL_PROMPT" if test -z "$POWERLINE_CONFIG"
if test -z "$POWERLINE_COMMAND" if which powerline-config >/dev/null
if false ;and which powerline-config >/dev/null set -g POWERLINE_CONFIG powerline-config
set -g -x POWERLINE_COMMAND (powerline-config shell command)
else else
set -l powerline_dir (dirname (status -f))/../../.. set -g POWERLINE_CONFIG (dirname (status -f))/../../../scripts/powerline-config
set -g -x POWERLINE_COMMAND (eval $powerline_dir/scripts/powerline-config shell command)
end end
end end
if eval $POWERLINE_CONFIG shell --shell=fish uses prompt
if test -z "$POWERLINE_COMMAND"
set -g POWERLINE_COMMAND (eval $POWERLINE_CONFIG shell command)
end
function --on-variable POWERLINE_COMMAND _powerline_update function --on-variable POWERLINE_COMMAND _powerline_update
set -l addargs "--last_exit_code=\$status" set -l addargs "--last_exit_code=\$status"
set -l addargs "$addargs --last_pipe_status=\$status" set -l addargs "$addargs --last_pipe_status=\$status"
@ -60,7 +63,7 @@ function powerline-setup
end end
_powerline_update _powerline_update
end end
if test -z "$POWERLINE_NO_FISH_TMUX_SUPPORT$POWERLINE_NO_SHELL_TMUX_SUPPORT" if eval $POWERLINE_CONFIG shell --shell=fish uses tmux
if test -n "$TMUX" if test -n "$TMUX"
if tmux refresh -S ^/dev/null if tmux refresh -S ^/dev/null
function _powerline_tmux_setenv function _powerline_tmux_setenv
@ -79,3 +82,4 @@ function powerline-setup
end end
end end
end end
# vim: ft=fish

View File

@ -47,7 +47,7 @@ class ConfigurableIpythonPowerline(IpythonPowerline):
config = ip.config.Powerline config = ip.config.Powerline
self.config_overrides = config.get('config_overrides') self.config_overrides = config.get('config_overrides')
self.theme_overrides = config.get('theme_overrides', {}) self.theme_overrides = config.get('theme_overrides', {})
self.path = config.get('path') self.paths = config.get('paths')
super(ConfigurableIpythonPowerline, self).__init__(is_prompt) super(ConfigurableIpythonPowerline, self).__init__(is_prompt)

View File

@ -82,10 +82,10 @@ class PowerlinePrompt2(PowerlinePromptOut):
class ConfigurableIpythonPowerline(IpythonPowerline): class ConfigurableIpythonPowerline(IpythonPowerline):
def __init__(self, is_prompt, config_overrides=None, theme_overrides={}, path=None): def __init__(self, is_prompt, config_overrides=None, theme_overrides={}, paths=None):
self.config_overrides = config_overrides self.config_overrides = config_overrides
self.theme_overrides = theme_overrides self.theme_overrides = theme_overrides
self.path = path self.paths = paths
super(ConfigurableIpythonPowerline, self).__init__(is_prompt) super(ConfigurableIpythonPowerline, self).__init__(is_prompt)

View File

@ -98,12 +98,7 @@ _powerline_set_set_jobs() {
_powerline_set_command() { _powerline_set_command() {
if test -z "${POWERLINE_COMMAND}" ; then if test -z "${POWERLINE_COMMAND}" ; then
if which powerline-config &>/dev/null ; then POWERLINE_COMMAND="$("$POWERLINE_CONFIG" shell command)"
export POWERLINE_COMMAND="$(powerline-config shell command)"
else
local powerline_dir="$(dirname "$POWERLINE_SOURCED")/../../.."
export POWERLINE_COMMAND="$($powerline_dir/scripts/powerline-config shell command)"
fi
fi fi
} }
@ -167,14 +162,22 @@ _powerline_init_tmux_support() {
fi fi
} }
if test -z "${POWERLINE_CONFIG}" ; then
if which powerline-config >/dev/null ; then
POWERLINE_CONFIG=powerline-config
else
POWERLINE_CONFIG="$(dirname "$_POWERLINE_SOURCED")/../../../scripts/powerline-config"
fi
fi
# Strips the leading `-`: it may be present when shell is a login shell # Strips the leading `-`: it may be present when shell is a login shell
_POWERLINE_USED_SHELL=${0#-} _POWERLINE_USED_SHELL=${0#-}
_POWERLINE_USED_SHELL=${_POWERLINE_USED_SHELL#/usr} _POWERLINE_USED_SHELL=${_POWERLINE_USED_SHELL#/usr}
_POWERLINE_USED_SHELL=${_POWERLINE_USED_SHELL#/bin/} _POWERLINE_USED_SHELL=${_POWERLINE_USED_SHELL#/bin/}
if test -z "$POWERLINE_NO_BB_PROMPT$POWERLINE_NO_SHELL_PROMPT" ; then if "${POWERLINE_CONFIG}" shell uses tmux ; then
_powerline_setup_prompt $_POWERLINE_USED_SHELL
fi
if test -z "$POWERLINE_NO_BB_TMUX_SUPPORT$POWERLINE_NO_SHELL_TMUX_SUPPORT" ; then
_powerline_init_tmux_support $_POWERLINE_USED_SHELL _powerline_init_tmux_support $_POWERLINE_USED_SHELL
fi fi
if "${POWERLINE_CONFIG}" shell --shell=bash uses prompt ; then
_powerline_setup_prompt $_POWERLINE_USED_SHELL
fi

View File

@ -5,17 +5,20 @@
# Guess this relies on `$_` being set as to last argument to previous command # Guess this relies on `$_` being set as to last argument to previous command
# which must be `.` or `source` in this case # which must be `.` or `source` in this case
set POWERLINE_SOURCED=($_) set POWERLINE_SOURCED=($_)
if ! ( $?POWERLINE_NO_TCSH_TMUX_SUPPORT || $?POWERLINE_NO_SHELL_TMUX_SUPPORT ) then if ! $?POWERLINE_CONFIG then
if ( { which powerline-config > /dev/null } ) then
set POWERLINE_CONFIG="powerline-config"
else
set POWERLINE_CONFIG="$POWERLINE_SOURCED[2]:h:h:h:h/scripts/powerline-config"
endif
endif
if ( { $POWERLINE_CONFIG shell --shell=tcsh uses tmux } ) then
alias _powerline_tmux_set_pwd 'if ( $?TMUX && { tmux refresh -S >&/dev/null } ) tmux setenv -g TMUX_PWD_`tmux display -p "#D" | tr -d %` $PWD:q ; if ( $?TMUX ) tmux refresh -S >&/dev/null' alias _powerline_tmux_set_pwd 'if ( $?TMUX && { tmux refresh -S >&/dev/null } ) tmux setenv -g TMUX_PWD_`tmux display -p "#D" | tr -d %` $PWD:q ; if ( $?TMUX ) tmux refresh -S >&/dev/null'
alias cwdcmd "`alias cwdcmd` ; _powerline_tmux_set_pwd" alias cwdcmd "`alias cwdcmd` ; _powerline_tmux_set_pwd"
endif endif
if ! ( $?POWERLINE_NO_TCSH_PROMPT || $?POWERLINE_NO_SHELL_PROMPT ) then if ( { $POWERLINE_CONFIG shell --shell=tcsh uses prompt } ) then
if ! $?POWERLINE_COMMAND then if ! $?POWERLINE_COMMAND then
if ( { which powerline-config > /dev/null } ) then set POWERLINE_COMMAND="`$POWERLINE_CONFIG:q shell command`"
setenv POWERLINE_COMMAND "`powerline-config shell command`"
else
setenv POWERLINE_COMMAND "`$POWERLINE_SOURCED[2]:h:h:h:h:q/scripts/powerline-config shell command`"
endif
endif endif
if ( $?POWERLINE_NO_TCSH_ABOVE || $?POWERLINE_NO_SHELL_ABOVE ) then if ( $?POWERLINE_NO_TCSH_ABOVE || $?POWERLINE_NO_SHELL_ABOVE ) then

View File

@ -99,10 +99,23 @@ else:
if hasattr(vim, 'options'): if hasattr(vim, 'options'):
def vim_getbufoption(info, option): def vim_getbufoption(info, option):
return info['buffer'].options[str(option)] return info['buffer'].options[str(option)]
def vim_getoption(option):
return vim.options[str(option)]
def vim_setoption(option, value):
vim.options[str(option)] = value
else: else:
def vim_getbufoption(info, option): # NOQA def vim_getbufoption(info, option): # NOQA
return getbufvar(info['bufnr'], '&' + option) return getbufvar(info['bufnr'], '&' + option)
def vim_getoption(option): # NOQA
return vim.eval('&g:' + option)
def vim_setoption(option, value): # NOQA
vim.command('let &g:{option} = {value}'.format(
option=option, value=json.encode(value)))
if hasattr(vim, 'tabpages'): if hasattr(vim, 'tabpages'):
current_tabpage = lambda: vim.current.tabpage current_tabpage = lambda: vim.current.tabpage

View File

@ -5,6 +5,7 @@ import zsh
import atexit import atexit
from powerline.shell import ShellPowerline from powerline.shell import ShellPowerline
from powerline.lib import parsedotval from powerline.lib import parsedotval
from powerline.lib.unicode import unicode
used_powerlines = [] used_powerlines = []
@ -44,9 +45,14 @@ class Args(object):
@property @property
def config_path(self): def config_path(self):
try: try:
return zsh.getvalue('POWERLINE_CONFIG_PATH') ret = zsh.getvalue('POWERLINE_CONFIG_PATHS')
except IndexError: except IndexError:
return None return None
else:
if isinstance(ret, (unicode, str, bytes)):
return ret.split(type(ret)(':'))
else:
return ret
@property @property
def jobnum(self): def jobnum(self):

View File

@ -126,12 +126,7 @@ _powerline_setup_prompt() {
zpython 'del _powerline_setup' zpython 'del _powerline_setup'
else else
if test -z "${POWERLINE_COMMAND}" ; then if test -z "${POWERLINE_COMMAND}" ; then
if which powerline-config &>/dev/null ; then POWERLINE_COMMAND=( "$($POWERLINE_CONFIG shell command)" )
export POWERLINE_COMMAND="$(powerline-config shell command)"
else
local powerline_dir="$POWERLINE_SOURCED:h:h:h:h"
export POWERLINE_COMMAND="$($powerline_dir/scripts/powerline-config shell command)"
fi
fi fi
local add_args='--last_exit_code=$?' local add_args='--last_exit_code=$?'
@ -176,12 +171,21 @@ _powerline_add_widget() {
fi fi
} }
if test -z "${POWERLINE_CONFIG}" ; then
if which powerline-config >/dev/null ; then
export POWERLINE_CONFIG=powerline-config
else
export POWERLINE_CONFIG="$_POWERLINE_SOURCED:h:h:h:h/scripts/powerline-config"
fi
fi
setopt promptpercent setopt promptpercent
setopt promptsubst setopt promptsubst
if test -z "$POWERLINE_NO_ZSH_PROMPT$POWERLINE_NO_SHELL_PROMPT" ; then
if ${POWERLINE_CONFIG} shell --shell=zsh uses prompt ; then
_powerline_setup_prompt _powerline_setup_prompt
_powerline_init_modes_support _powerline_init_modes_support
fi fi
if test -z "$POWERLINE_NO_ZSH_TMUX_SUPPORT$POWERLINE_NO_SHELL_TMUX_SUPPORT" ; then if ${POWERLINE_CONFIG} shell --shell=zsh uses tmux ; then
_powerline_init_tmux_support _powerline_init_tmux_support
fi fi

View File

@ -31,8 +31,8 @@ class IpythonPowerline(Powerline):
) )
def get_config_paths(self): def get_config_paths(self):
if self.path: if self.paths:
return [self.path] return self.paths
else: else:
return super(IpythonPowerline, self).get_config_paths() return super(IpythonPowerline, self).get_config_paths()

View File

@ -8,6 +8,7 @@ from powerline.segments.vim import vim_modes
from powerline.lint.inspect import getconfigargspec from powerline.lint.inspect import getconfigargspec
from powerline.lib.threaded import ThreadedSegment from powerline.lib.threaded import ThreadedSegment
from powerline.lib import mergedicts_copy from powerline.lib import mergedicts_copy
from powerline.lib.unicode import unicode
import itertools import itertools
import sys import sys
import os import os
@ -17,12 +18,6 @@ from copy import copy
import logging import logging
try:
from __builtin__ import unicode
except ImportError:
unicode = str
def open_file(path): def open_file(path):
return open(path, 'rb') return open(path, 'rb')
@ -530,6 +525,7 @@ ext_spec = Spec(
theme=ext_theme_spec(), theme=ext_theme_spec(),
top_theme=top_theme_spec().optional(), top_theme=top_theme_spec().optional(),
).copy ).copy
gen_components_spec = (lambda *components: Spec().list(Spec().type(unicode).oneof(set(components))))
main_spec = (Spec( main_spec = (Spec(
common=Spec( common=Spec(
default_top_theme=top_theme_spec().optional(), default_top_theme=top_theme_spec().optional(),
@ -561,6 +557,7 @@ main_spec = (Spec(
).context_message('Error while loading common configuration (key {key})'), ).context_message('Error while loading common configuration (key {key})'),
ext=Spec( ext=Spec(
vim=ext_spec().update( vim=ext_spec().update(
components=gen_components_spec('statusline', 'tabline').optional(),
local_themes=Spec( local_themes=Spec(
__tabline__=ext_theme_spec(), __tabline__=ext_theme_spec(),
).unknown_spec( ).unknown_spec(
@ -575,6 +572,7 @@ main_spec = (Spec(
), ),
).optional(), ).optional(),
shell=ext_spec().update( shell=ext_spec().update(
components=gen_components_spec('tmux', 'prompt').optional(),
local_themes=Spec( local_themes=Spec(
continuation=ext_theme_spec(), continuation=ext_theme_spec(),
select=ext_theme_spec(), select=ext_theme_spec(),
@ -1078,8 +1076,8 @@ def list_themes(data, context):
is_main_theme = (data['theme'] == main_theme_name) is_main_theme = (data['theme'] == main_theme_name)
if theme_type == 'top': if theme_type == 'top':
return list(itertools.chain(*[ return list(itertools.chain(*[
[(ext, theme) for theme in theme_configs.values()] [(theme_ext, theme) for theme in theme_configs.values()]
for ext, theme_configs in data['theme_configs'].items() for theme_ext, theme_configs in data['theme_configs'].items()
])) ]))
elif theme_type == 'main' or is_main_theme: elif theme_type == 'main' or is_main_theme:
return [(ext, theme) for theme in data['ext_theme_configs'].values()] return [(ext, theme) for theme in data['ext_theme_configs'].values()]

View File

@ -1,7 +1,5 @@
# vim:fileencoding=utf-8:noet # vim:fileencoding=utf-8:noet
import os
from powerline import Powerline from powerline import Powerline
from powerline.lib import mergedicts, parsedotval from powerline.lib import mergedicts, parsedotval
@ -82,7 +80,7 @@ def write_output(args, powerline, segment_info, write):
for line in powerline.render_above_lines( for line in powerline.render_above_lines(
width=args.width, width=args.width,
segment_info=segment_info, segment_info=segment_info,
mode=os.environ.get('_POWERLINE_MODE'), mode=segment_info['environ'].get('_POWERLINE_MODE'),
): ):
write(line) write(line)
write('\n') write('\n')
@ -93,6 +91,6 @@ def write_output(args, powerline, segment_info, write):
width=args.width, width=args.width,
side=args.side, side=args.side,
segment_info=segment_info, segment_info=segment_info,
mode=os.environ.get('_POWERLINE_MODE'), mode=segment_info['environ'].get('_POWERLINE_MODE'),
) )
write(rendered) write(rendered)

View File

@ -27,6 +27,7 @@ class VimPowerline(Powerline):
def __init__(self, pyeval='PowerlinePyeval', **kwargs): def __init__(self, pyeval='PowerlinePyeval', **kwargs):
super(VimPowerline, self).__init__('vim', **kwargs) super(VimPowerline, self).__init__('vim', **kwargs)
self.last_window_id = 1 self.last_window_id = 1
self.pyeval = pyeval
self.window_statusline = '%!' + pyeval + '(\'powerline.statusline({0})\')' self.window_statusline = '%!' + pyeval + '(\'powerline.statusline({0})\')'
def add_local_theme(self, key, config): def add_local_theme(self, key, config):
@ -154,11 +155,23 @@ class VimPowerline(Powerline):
# requirements to __main__ globals to just one powerline object # requirements to __main__ globals to just one powerline object
# (previously it required as well vim and json) # (previously it required as well vim and json)
@staticmethod @staticmethod
def pyeval(): def do_pyeval():
import __main__ import __main__
vim.command('return ' + json.dumps(eval(vim.eval('a:e'), vim.command('return ' + json.dumps(eval(vim.eval('a:e'),
__main__.__dict__))) __main__.__dict__)))
def setup_components(self, components):
if components is None:
components = ('statusline', 'tabline')
if 'statusline' in components:
# Is immediately changed after new_window function is run. Good for
# global value.
vim.command('set statusline=%!{pyeval}(\'powerline.new_window()\')'.format(
pyeval=self.pyeval))
if 'tabline' in components:
vim.command('set tabline=%!{pyeval}(\'powerline.tabline()\')'.format(
pyeval=self.pyeval))
pycmd = None pycmd = None
@ -186,12 +199,13 @@ def setup(pyeval=None, pycmd=None, can_replace_pyeval=True):
if not hasattr(vim, 'bindeval') and can_replace_pyeval: if not hasattr(vim, 'bindeval') and can_replace_pyeval:
vim.command((''' vim.command(('''
function! PowerlinePyeval(e) function! PowerlinePyeval(e)
{pycmd} powerline.pyeval() {pycmd} powerline.do_pyeval()
endfunction endfunction
''').format(pycmd=pycmd)) ''').format(pycmd=pycmd))
pyeval = 'PowerlinePyeval' pyeval = 'PowerlinePyeval'
powerline = VimPowerline(pyeval) powerline = VimPowerline(pyeval)
powerline.update_renderer()
__main__.powerline = powerline __main__.powerline = powerline
# Cannot have this in one line due to weird newline handling (in :execute # Cannot have this in one line due to weird newline handling (in :execute
@ -202,8 +216,3 @@ def setup(pyeval=None, pycmd=None, can_replace_pyeval=True):
vim.command(' autocmd! ColorScheme * :{pycmd} powerline.reset_highlight()'.format(pycmd=pycmd)) vim.command(' autocmd! ColorScheme * :{pycmd} powerline.reset_highlight()'.format(pycmd=pycmd))
vim.command(' autocmd! VimLeavePre * :{pycmd} powerline.shutdown()'.format(pycmd=pycmd)) vim.command(' autocmd! VimLeavePre * :{pycmd} powerline.shutdown()'.format(pycmd=pycmd))
vim.command('augroup END') vim.command('augroup END')
# Is immediately changed after new_window function is run. Good for global
# value.
vim.command('set statusline=%!{pyeval}(\'powerline.new_window()\')'.format(pyeval=pyeval))
vim.command('set tabline=%!{pyeval}(\'powerline.tabline()\')'.format(pyeval=pyeval))

View File

@ -20,6 +20,7 @@ TMUX_ACTIONS = {
SHELL_ACTIONS = { SHELL_ACTIONS = {
'command': config.shell_command, 'command': config.shell_command,
'uses': config.uses,
} }
@ -40,7 +41,19 @@ if __name__ == '__main__':
'function', 'function',
choices=tuple(SHELL_ACTIONS.values()), choices=tuple(SHELL_ACTIONS.values()),
type=(lambda v: SHELL_ACTIONS.get(v)), type=(lambda v: SHELL_ACTIONS.get(v)),
help='If action is "command" then preferred powerline command is output', metavar='action',
help='If action is "command" then preferred powerline command is output, if it is “uses” then powerline-config script will exit with 1 if specified component is disabled and 0 otherwise.',
)
shell_parser.add_argument(
'component',
nargs='?',
choices=('tmux', 'prompt'),
metavar='component',
)
shell_parser.add_argument(
'-s', '--shell',
nargs='?',
help='Shell for which query is run',
) )
args = parser.parse_args() args = parser.parse_args()

View File

@ -112,7 +112,7 @@ class TestConfig(TestCase):
from powerline.ipython import IpythonPowerline from powerline.ipython import IpythonPowerline
class IpyPowerline(IpythonPowerline): class IpyPowerline(IpythonPowerline):
path = None paths = None
config_overrides = None config_overrides = None
theme_overrides = {} theme_overrides = {}

View File

@ -1,4 +1,4 @@
set fish_function_path $fish_function_path "$PWD/powerline/bindings/fish" set fish_function_path "$PWD/powerline/bindings/fish" $fish_function_path
powerline-setup powerline-setup
set POWERLINE_COMMAND "$POWERLINE_COMMAND -p $PWD/powerline/config_files" set POWERLINE_COMMAND "$POWERLINE_COMMAND -p $PWD/powerline/config_files"
set POWERLINE_COMMAND "$POWERLINE_COMMAND -t default_leftonly.segment_data.hostname.args.only_if_ssh=false" set POWERLINE_COMMAND "$POWERLINE_COMMAND -t default_leftonly.segment_data.hostname.args.only_if_ssh=false"

View File

@ -1,10 +1,10 @@
source powerline/bindings/tcsh/powerline.tcsh source powerline/bindings/tcsh/powerline.tcsh
setenv POWERLINE_COMMAND "$POWERLINE_COMMAND -p "$PWD:q/powerline/config_files" -t default_leftonly.segment_data.hostname.args.only_if_ssh=false -c ext.shell.theme=default_leftonly" set POWERLINE_COMMAND=$POWERLINE_COMMAND:q" -p "$PWD:q/powerline/config_files" -t default_leftonly.segment_data.hostname.args.only_if_ssh=false -c ext.shell.theme=default_leftonly"
unsetenv VIRTUAL_ENV unsetenv VIRTUAL_ENV
cd tests/shell/3rd cd tests/shell/3rd
cd .git cd .git
cd .. cd ..
setenv VIRTUAL_ENV $HOME:q"/.virtenvs/some-virtual-environment" setenv VIRTUAL_ENV "/home/foo/.virtenvs/some-virtual-environment"
unsetenv VIRTUAL_ENV unsetenv VIRTUAL_ENV
bash -c 'echo $$>pid ; while true ; do sleep 0.1s ; done' & bash -c 'echo $$>pid ; while true ; do sleep 0.1s ; done' &
false # Warning: currently tcsh bindings do not support job count false # Warning: currently tcsh bindings do not support job count

View File

@ -1,6 +1,8 @@
import os
c = get_config() c = get_config()
c.InteractiveShellApp.extensions = ['powerline.bindings.ipython.post_0_11'] c.InteractiveShellApp.extensions = ['powerline.bindings.ipython.post_0_11']
c.TerminalInteractiveShell.autocall = 1 c.TerminalInteractiveShell.autocall = 1
c.Powerline.paths = [os.path.abspath('powerline/config_files')]
c.Powerline.theme_overrides = { c.Powerline.theme_overrides = {
'in': { 'in': {
'segment_data': { 'segment_data': {

View File

@ -17,6 +17,25 @@ check_screen_log() {
fi fi
} }
run() {
local local_path="$PWD/tests/shell/path:$PWD/scripts"
if test "x$SH" = "xfish" ; then
local_path="${local_path}:/usr/bin:/bin"
fi
env -i \
PATH="$local_path" \
TERM="${TERM}" \
COLUMNS="${COLUMNS}" \
LINES="${LINES}" \
TEST_TYPE="${TEST_TYPE}" \
SH="${SH}" \
DIR1="${DIR1}" \
DIR2="${DIR2}" \
XDG_CONFIG_HOME="$PWD/tests/shell/fish_home" \
IPYTHONDIR="$PWD/tests/shell/ipython_home" \
"$@"
}
run_test() { run_test() {
TEST_TYPE="$1" TEST_TYPE="$1"
shift shift
@ -41,7 +60,7 @@ run_test() {
export TEST_TYPE export TEST_TYPE
export SH export SH
screen -L -c tests/test_shells/screenrc -d -m -S "$SESNAME" \ run screen -L -c tests/test_shells/screenrc -d -m -S "$SESNAME" \
env LANG=en_US.UTF-8 BINDFILE="$BINDFILE" "${ARGS[@]}" env LANG=en_US.UTF-8 BINDFILE="$BINDFILE" "${ARGS[@]}"
screen -S "$SESNAME" -X readreg a tests/test_shells/input.$SH screen -S "$SESNAME" -X readreg a tests/test_shells/input.$SH
# Wait for screen to initialize # Wait for screen to initialize
@ -121,12 +140,45 @@ mkdir tests/shell/3rd/'`echo`'
mkdir tests/shell/fish_home mkdir tests/shell/fish_home
cp -r tests/test_shells/ipython_home tests/shell cp -r tests/test_shells/ipython_home tests/shell
export XDG_CONFIG_HOME="$PWD/tests/shell/fish_home"
export IPYTHONDIR="$PWD/tests/shell/ipython_home" mkdir tests/shell/path
ln -s "$(which "${PYTHON:-python}")" tests/shell/path/python
ln -s "$(which screen)" tests/shell/path
ln -s "$(which env)" tests/shell/path
ln -s "$(which sleep)" tests/shell/path
ln -s "$(which cat)" tests/shell/path
ln -s "$(which false)" tests/shell/path
ln -s "$(which true)" tests/shell/path
ln -s "$(which kill)" tests/shell/path
ln -s "$(which echo)" tests/shell/path
ln -s "$(which which)" tests/shell/path
ln -s "$(which dirname)" tests/shell/path
ln -s "$(which wc)" tests/shell/path
ln -s "$(which stty)" tests/shell/path
ln -s "$(which cut)" tests/shell/path
ln -s "$(which bc)" tests/shell/path
ln -s "$(which expr)" tests/shell/path
ln -s "$(which mktemp)" tests/shell/path
for pexe in powerline powerline-config ; do
if test -e scripts/$pexe ; then
ln -s "$PWD/scripts/$pexe" tests/shell/path
elif which $pexe ; then
ln -s "$(which $pexe)" tests/shell/path
else
echo "Executable $pexe was not found"
exit 1
fi
done
for exe in bash zsh bb busybox fish tcsh mksh dash ipython ; do
if which $exe >/dev/null ; then
ln -s "$(which $exe)" tests/shell/path
fi
done
unset ENV unset ENV
if test "x${ONLY_SHELL%sh}" != "x${ONLY_SHELL}" || test "x${ONLY_SHELL}" = xbb ; then if test -z "${ONLY_SHELL}" || test "x${ONLY_SHELL%sh}" != "x${ONLY_SHELL}" || test "x${ONLY_SHELL}" = xbb ; then
powerline-daemon -k || true powerline-daemon -k || true
sleep 1s sleep 1s
@ -183,5 +235,5 @@ if ! run_test ipython ipython ; then
FAILED=1 FAILED=1
fi fi
test "x$ONLY_SHELL" = "x" && rm -r tests/shell test $FAILED -eq 0 && rm -r tests/shell
exit $FAILED exit $FAILED

Binary file not shown.

View File

@ -211,8 +211,15 @@ def command(cmd):
if not aucmd.startswith(':python3 '): if not aucmd.startswith(':python3 '):
raise NotImplementedError raise NotImplementedError
_on_wipeout.append(aucmd.partition(' ')[2]) _on_wipeout.append(aucmd.partition(' ')[2])
elif cmd.startswith('set '):
if cmd.startswith('set statusline='):
options['statusline'] = cmd[len('set statusline='):]
elif cmd.startswith('set tabline='):
options['tabline'] = cmd[len('set tabline='):]
else: else:
raise NotImplementedError raise NotImplementedError(cmd)
else:
raise NotImplementedError(cmd)
@_vim @_vim
@ -481,6 +488,7 @@ class _Tabpage(object):
return win return win
def _close(self): def _close(self):
global _tabpage
while self.windows: while self.windows:
self._close_window(1, False) self._close_window(1, False)
tabpages._pop(self.number) tabpages._pop(self.number)
@ -680,6 +688,7 @@ def _edit(name=None):
@_vim @_vim
def _tabnew(name=None): def _tabnew(name=None):
global windows global windows
global _tabpage
tabpage = tabpages._new() tabpage = tabpages._new()
windows = tabpage.windows windows = tabpage.windows
_tabpage = len(tabpages) _tabpage = len(tabpages)