Use new `zsh.expand` function in place of `zsh.eval`

This commit is contained in:
ZyX 2015-01-25 02:06:35 +03:00
parent ab4021a273
commit 96571cc47b
1 changed files with 14 additions and 6 deletions

View File

@ -107,6 +107,16 @@ else:
environ = Environment() environ = Environment()
if hasattr(zsh, 'expand') and zsh.expand('${:-}') == '':
zsh_expand = zsh.expand
else:
def zsh_expand(s):
zsh.eval('_POWERLINE_REPLY="' + s + '"')
ret = zsh.getvalue('_POWERLINE_REPLY')
zsh.setvalue('_POWERLINE_REPLY', None)
return ret
class ZshPowerline(ShellPowerline): class ZshPowerline(ShellPowerline):
def init(self, **kwargs): def init(self, **kwargs):
super(ZshPowerline, self).init(Args(), **kwargs) super(ZshPowerline, self).init(Args(), **kwargs)
@ -138,8 +148,8 @@ class Prompt(object):
self.theme = theme self.theme = theme
def __str__(self): def __str__(self):
zsh.eval('_POWERLINE_PARSER_STATE="${(%):-%_}"') parser_state = u(zsh_expand('${(%):-%_}'))
zsh.eval('_POWERLINE_SHORTENED_PATH="${(%):-%~}"') shortened_path = u(zsh_expand('${(%):-%~}'))
try: try:
mode = u(zsh.getvalue('_POWERLINE_MODE')) mode = u(zsh.getvalue('_POWERLINE_MODE'))
except IndexError: except IndexError:
@ -153,13 +163,11 @@ class Prompt(object):
'environ': environ, 'environ': environ,
'client_id': 1, 'client_id': 1,
'local_theme': self.theme, 'local_theme': self.theme,
'parser_state': zsh.getvalue('_POWERLINE_PARSER_STATE'), 'parser_state': parser_state,
'shortened_path': zsh.getvalue('_POWERLINE_SHORTENED_PATH'), 'shortened_path': shortened_path,
'mode': mode, 'mode': mode,
'default_mode': default_mode, 'default_mode': default_mode,
} }
zsh.setvalue('_POWERLINE_PARSER_STATE', None)
zsh.setvalue('_POWERLINE_SHORTENED_PATH', None)
try: try:
zle_rprompt_indent = zsh.getvalue('ZLE_RPROMPT_INDENT') zle_rprompt_indent = zsh.getvalue('ZLE_RPROMPT_INDENT')
except IndexError: except IndexError: