Merge pull request #1014 from ZyX-I/zsh-named-dirs

Add support for zsh named directories
This commit is contained in:
Nikolai Aleksandrovich Pavlov 2014-08-24 20:08:20 +04:00
commit d4525a8086
20 changed files with 302 additions and 97 deletions

View File

@ -2,7 +2,7 @@
from sphinx.ext import autodoc from sphinx.ext import autodoc
from inspect import formatargspec from inspect import formatargspec
from powerline.lint.inspect import getconfigargspec from powerline.lint.inspect import getconfigargspec
from powerline.lib.threaded import ThreadedSegment from powerline.segments import Segment
try: try:
from __builtin__ import unicode from __builtin__ import unicode
@ -21,7 +21,7 @@ class ThreadedDocumenter(autodoc.FunctionDocumenter):
'''Specialized documenter subclass for ThreadedSegment subclasses.''' '''Specialized documenter subclass for ThreadedSegment subclasses.'''
@classmethod @classmethod
def can_document_member(cls, member, membername, isattr, parent): def can_document_member(cls, member, membername, isattr, parent):
return (isinstance(member, ThreadedSegment) or return (isinstance(member, Segment) or
super(ThreadedDocumenter, cls).can_document_member(member, membername, isattr, parent)) super(ThreadedDocumenter, cls).can_document_member(member, membername, isattr, parent))
def format_args(self): def format_args(self):

View File

@ -135,6 +135,7 @@ class Prompt(object):
'client_id': 1, 'client_id': 1,
'local_theme': self.theme, 'local_theme': self.theme,
'parser_state': zsh.getvalue('_POWERLINE_PARSER_STATE'), 'parser_state': zsh.getvalue('_POWERLINE_PARSER_STATE'),
'shortened_path': zsh.getvalue('_POWERLINE_SHORTENED_PATH'),
} }
r = '' r = ''
if self.above: if self.above:

View File

@ -103,6 +103,10 @@ _powerline_set_jobnum() {
_POWERLINE_JOBNUM=${(%):-%j} _POWERLINE_JOBNUM=${(%):-%j}
} }
_powerline_set_shortened_path() {
_POWERLINE_SHORTENED_PATH="${(%):-%~}"
}
_powerline_update_counter() { _powerline_update_counter() {
zpython '_powerline.precmd()' zpython '_powerline.precmd()'
} }
@ -116,6 +120,8 @@ _powerline_setup_prompt() {
fi fi
done done
precmd_functions+=( _powerline_set_jobnum ) precmd_functions+=( _powerline_set_jobnum )
chpwd_functions+=( _powerline_set_shortened_path )
_powerline_set_shortened_path
VIRTUAL_ENV_DISABLE_PROMPT=1 VIRTUAL_ENV_DISABLE_PROMPT=1
@ -138,6 +144,7 @@ _powerline_setup_prompt() {
add_args+=' --last_exit_code=$?' add_args+=' --last_exit_code=$?'
add_args+=' --last_pipe_status="$pipestatus"' add_args+=' --last_pipe_status="$pipestatus"'
add_args+=' --renderer_arg="client_id=$$"' add_args+=' --renderer_arg="client_id=$$"'
add_args+=' --renderer_arg="shortened_path=$_POWERLINE_SHORTENED_PATH"'
add_args+=' --jobnum=$_POWERLINE_JOBNUM' add_args+=' --jobnum=$_POWERLINE_JOBNUM'
local new_args_2=' --renderer_arg="parser_state=${(%%):-%_}"' local new_args_2=' --renderer_arg="parser_state=${(%%):-%_}"'
new_args_2+=' --renderer_arg="local_theme=continuation"' new_args_2+=' --renderer_arg="local_theme=continuation"'

View File

@ -14,16 +14,16 @@
"branch": { "branch": {
"before": "BR " "before": "BR "
}, },
"cwd": {
"args": {
"ellipsis": "..."
}
},
"line_current_symbol": { "line_current_symbol": {
"contents": "LN " "contents": "LN "
}, },
"powerline.segments.common.cwd": {
"args": {
"ellipsis": "..."
}
},
"powerline.segments.common.network_load": { "powerline.segments.common.network_load": {
"args": { "args": {
"recv_format": "DL {value:>8}", "recv_format": "DL {value:>8}",

View File

@ -14,16 +14,16 @@
"branch": { "branch": {
"before": " " "before": " "
}, },
"cwd": {
"args": {
"ellipsis": "⋯"
}
},
"line_current_symbol": { "line_current_symbol": {
"contents": " " "contents": " "
}, },
"powerline.segments.common.cwd": {
"args": {
"ellipsis": "⋯"
}
},
"powerline.segments.common.network_load": { "powerline.segments.common.network_load": {
"args": { "args": {
"recv_format": "⬇ {value:>8}", "recv_format": "⬇ {value:>8}",

View File

@ -5,7 +5,7 @@
"only_if_ssh": true "only_if_ssh": true
} }
}, },
"powerline.segments.common.cwd": { "cwd": {
"args": { "args": {
"dir_limit_depth": 3 "dir_limit_depth": 3
} }

View File

@ -19,6 +19,7 @@
"priority": 50 "priority": 50
}, },
{ {
"module": "powerline.segments.shell",
"name": "cwd", "name": "cwd",
"priority": 10 "priority": 10
}, },

View File

@ -19,6 +19,7 @@
"priority": 40 "priority": 40
}, },
{ {
"module": "powerline.segments.shell",
"name": "cwd", "name": "cwd",
"priority": 10 "priority": 10
}, },

View File

@ -14,16 +14,16 @@
"branch": { "branch": {
"before": "⎇ " "before": "⎇ "
}, },
"cwd": {
"args": {
"ellipsis": "⋯"
}
},
"line_current_symbol": { "line_current_symbol": {
"contents": "␤ " "contents": "␤ "
}, },
"powerline.segments.common.cwd": {
"args": {
"ellipsis": "⋯"
}
},
"powerline.segments.common.network_load": { "powerline.segments.common.network_load": {
"args": { "args": {
"recv_format": "⬇ {value:>8}", "recv_format": "⬇ {value:>8}",

View File

@ -14,16 +14,16 @@
"branch": { "branch": {
"before": "BR " "before": "BR "
}, },
"cwd": {
"args": {
"ellipsis": "…"
}
},
"line_current_symbol": { "line_current_symbol": {
"contents": "␤ " "contents": "␤ "
}, },
"powerline.segments.common.cwd": {
"args": {
"ellipsis": "…"
}
},
"powerline.segments.common.network_load": { "powerline.segments.common.network_load": {
"args": { "args": {
"recv_format": "⇓ {value:>8}", "recv_format": "⇓ {value:>8}",

View File

@ -14,17 +14,17 @@
"branch": { "branch": {
"before": "B " "before": "B "
}, },
"cwd": {
"line_current_symbol": {
"contents": "␤"
},
"powerline.segments.common.cwd": {
"args": { "args": {
"use_path_separator": true, "use_path_separator": true,
"ellipsis": "…" "ellipsis": "…"
} }
}, },
"line_current_symbol": {
"contents": "␤"
},
"powerline.segments.common.network_load": { "powerline.segments.common.network_load": {
"args": { "args": {
"recv_format": "⇓{value:>8}", "recv_format": "⇓{value:>8}",

View File

@ -256,8 +256,3 @@ class KwThreadedSegment(ThreadedSegment):
@staticmethod @staticmethod
def render_one(update_state, **kwargs): def render_one(update_state, **kwargs):
return update_state return update_state
def with_docstring(instance, doc):
instance.__doc__ = doc
return instance

View File

@ -40,7 +40,7 @@ class Segment(object):
'''List arguments which should be omitted '''List arguments which should be omitted
Returns a tuple with indexes of omitted arguments. Returns a tuple with indexes of omitted arguments.
.. note::``segment_info``, ``create_watcher`` and ``pl`` will be omitted .. note::``segment_info``, ``create_watcher`` and ``pl`` will be omitted
regardless of the below return (for ``segment_info`` and regardless of the below return (for ``segment_info`` and
``create_watcher``: only if object was marked to require segment ``create_watcher``: only if object was marked to require segment
@ -56,3 +56,8 @@ class Segment(object):
'''Returns a list of (additional argument name[, default value]) tuples. '''Returns a list of (additional argument name[, default value]) tuples.
''' '''
return () return ()
def with_docstring(instance, doc):
instance.__doc__ = doc
return instance

View File

@ -15,12 +15,12 @@ from powerline.lib import add_divider_highlight_group
from powerline.lib.shell import asrun, run_cmd from powerline.lib.shell import asrun, run_cmd
from powerline.lib.url import urllib_read, urllib_urlencode from powerline.lib.url import urllib_read, urllib_urlencode
from powerline.lib.vcs import guess, tree_status from powerline.lib.vcs import guess, tree_status
from powerline.lib.threaded import ThreadedSegment, KwThreadedSegment, with_docstring from powerline.lib.threaded import ThreadedSegment, KwThreadedSegment
from powerline.lib.monotonic import monotonic from powerline.lib.monotonic import monotonic
from powerline.lib.humanize_bytes import humanize_bytes from powerline.lib.humanize_bytes import humanize_bytes
from powerline.lib.unicode import u from powerline.lib.unicode import u
from powerline.theme import requires_segment_info, requires_filesystem_watcher from powerline.theme import requires_segment_info, requires_filesystem_watcher
from powerline.segments import Segment from powerline.segments import Segment, with_docstring
from collections import namedtuple from collections import namedtuple
@ -82,68 +82,96 @@ def branch(pl, segment_info, create_watcher, status_colors=False):
@requires_segment_info @requires_segment_info
def cwd(pl, segment_info, dir_shorten_len=None, dir_limit_depth=None, use_path_separator=False, ellipsis=''): class CwdSegment(Segment):
'''Return the current working directory. def argspecobjs(self):
for obj in super(CwdSegment, self).argspecobjs():
yield obj
yield 'get_shortened_path', self.get_shortened_path
Returns a segment list to create a breadcrumb-like effect. def omitted_args(self, name, method):
if method is self.get_shortened_path:
:param int dir_shorten_len: return (0, 1, 2)
shorten parent directory names to this length (e.g.
:file:`/long/path/to/powerline` :file:`/l/p/t/powerline`)
:param int dir_limit_depth:
limit directory depth to this number (e.g.
:file:`/long/path/to/powerline` :file:`/to/powerline`)
:param bool use_path_separator:
Use path separator in place of soft divider.
:param str ellipsis:
Specifies what to use in place of omitted directories. Use None to not
show this subsegment at all.
Divider highlight group used: ``cwd:divider``.
Highlight groups used: ``cwd:current_folder`` or ``cwd``. It is recommended to define all highlight groups.
'''
try:
cwd = u(segment_info['getcwd']())
except OSError as e:
if e.errno == 2:
# user most probably deleted the directory
# this happens when removing files from Mercurial repos for example
pl.warn('Current directory not found')
cwd = "[not found]"
else: else:
raise return super(CwdSegment, self).omitted_args(name, method)
home = segment_info['home']
if home: def get_shortened_path(self, pl, segment_info, shorten_home=True, **kwargs):
home = u(home) try:
cwd = re.sub('^' + re.escape(home), '~', cwd, 1) path = u(segment_info['getcwd']())
cwd_split = cwd.split(os.sep) except OSError as e:
cwd_split_len = len(cwd_split) if e.errno == 2:
cwd = [i[0:dir_shorten_len] if dir_shorten_len and i else i for i in cwd_split[:-1]] + [cwd_split[-1]] # user most probably deleted the directory
if dir_limit_depth and cwd_split_len > dir_limit_depth + 1: # this happens when removing files from Mercurial repos for example
del(cwd[0:-dir_limit_depth]) pl.warn('Current directory not found')
if ellipsis is not None: return "[not found]"
cwd.insert(0, ellipsis) else:
ret = [] raise
if not cwd[0]: if shorten_home:
cwd[0] = '/' home = segment_info['home']
draw_inner_divider = not use_path_separator if home:
for part in cwd: home = u(home)
if not part: if path.startswith(home):
continue path = '~' + path[len(home):]
return path
def __call__(self, pl, segment_info,
dir_shorten_len=None,
dir_limit_depth=None,
use_path_separator=False,
ellipsis='',
**kwargs):
cwd = self.get_shortened_path(pl, segment_info, **kwargs)
cwd_split = cwd.split(os.sep)
cwd_split_len = len(cwd_split)
cwd = [i[0:dir_shorten_len] if dir_shorten_len and i else i for i in cwd_split[:-1]] + [cwd_split[-1]]
if dir_limit_depth and cwd_split_len > dir_limit_depth + 1:
del(cwd[0:-dir_limit_depth])
if ellipsis is not None:
cwd.insert(0, ellipsis)
ret = []
if not cwd[0]:
cwd[0] = '/'
draw_inner_divider = not use_path_separator
for part in cwd:
if not part:
continue
if use_path_separator:
part += os.sep
ret.append({
'contents': part,
'divider_highlight_group': 'cwd:divider',
'draw_inner_divider': draw_inner_divider,
})
ret[-1]['highlight_group'] = ['cwd:current_folder', 'cwd']
if use_path_separator: if use_path_separator:
part += os.sep ret[-1]['contents'] = ret[-1]['contents'][:-1]
ret.append({ if len(ret) > 1 and ret[0]['contents'][0] == os.sep:
'contents': part, ret[0]['contents'] = ret[0]['contents'][1:]
'divider_highlight_group': 'cwd:divider', return ret
'draw_inner_divider': draw_inner_divider,
})
ret[-1]['highlight_group'] = ['cwd:current_folder', 'cwd'] cwd = with_docstring(CwdSegment(),
if use_path_separator: '''Return the current working directory.
ret[-1]['contents'] = ret[-1]['contents'][:-1]
if len(ret) > 1 and ret[0]['contents'][0] == os.sep: Returns a segment list to create a breadcrumb-like effect.
ret[0]['contents'] = ret[0]['contents'][1:]
return ret :param int dir_shorten_len:
shorten parent directory names to this length (e.g.
:file:`/long/path/to/powerline` :file:`/l/p/t/powerline`)
:param int dir_limit_depth:
limit directory depth to this number (e.g.
:file:`/long/path/to/powerline` :file:`/to/powerline`)
:param bool use_path_separator:
Use path separator in place of soft divider.
:param bool shorten_home:
Shorten home directory to ``~``.
:param str ellipsis:
Specifies what to use in place of omitted directories. Use None to not
show this subsegment at all.
Divider highlight group used: ``cwd:divider``.
Highlight groups used: ``cwd:current_folder`` or ``cwd``. It is recommended to define all highlight groups.
''')
def date(pl, format='%Y-%m-%d', istime=False): def date(pl, format='%Y-%m-%d', istime=False):

View File

@ -1,6 +1,8 @@
# vim:fileencoding=utf-8:noet # vim:fileencoding=utf-8:noet
from powerline.theme import requires_segment_info from powerline.theme import requires_segment_info
from powerline.segments import with_docstring
from powerline.segments.common import CwdSegment
@requires_segment_info @requires_segment_info
@ -120,3 +122,42 @@ def continuation(pl, segment_info, omit_cmdsubst=True, right_align=False, rename
ret[-1].update(width='auto', align='l', highlight_group=['continuation:current', 'continuation']) ret[-1].update(width='auto', align='l', highlight_group=['continuation:current', 'continuation'])
return ret return ret
@requires_segment_info
class ShellCwdSegment(CwdSegment):
def get_shortened_path(self, pl, segment_info, use_shortened_path=True, **kwargs):
if use_shortened_path:
try:
return segment_info['shortened_path']
except KeyError:
pass
return super(ShellCwdSegment, self).get_shortened_path(pl, segment_info, **kwargs)
cwd = with_docstring(ShellCwdSegment(),
'''Return the current working directory.
Returns a segment list to create a breadcrumb-like effect.
:param int dir_shorten_len:
shorten parent directory names to this length (e.g.
:file:`/long/path/to/powerline` :file:`/l/p/t/powerline`)
:param int dir_limit_depth:
limit directory depth to this number (e.g.
:file:`/long/path/to/powerline` :file:`/to/powerline`)
:param bool use_path_separator:
Use path separator in place of soft divider.
:param bool use_shortened_path:
Use path from shortened_path ``--renderer_arg`` argument. If this argument
is present ``shorten_home`` argument is ignored.
:param bool shorten_home:
Shorten home directory to ``~``.
:param str ellipsis:
Specifies what to use in place of omitted directories. Use None to not
show this subsegment at all.
Divider highlight group used: ``cwd:divider``.
Highlight groups used: ``cwd:current_folder`` or ``cwd``. It is recommended to define all highlight groups.
''')

View File

@ -162,6 +162,122 @@ class TestShell(TestCase):
}, },
]) ])
def test_cwd(self):
new_os = new_module('os', path=os.path, sep='/')
pl = Pl()
cwd = [None]
def getcwd():
wd = cwd[0]
if isinstance(wd, Exception):
raise wd
else:
return wd
segment_info = {'getcwd': getcwd, 'home': None}
with replace_attr(shell, 'os', new_os):
cwd[0] = '/abc/def/ghi/foo/bar'
self.assertEqual(common.cwd(pl=pl, segment_info=segment_info), [
{'contents': '/', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True},
{'contents': 'abc', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True},
{'contents': 'def', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True},
{'contents': 'ghi', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True},
{'contents': 'foo', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True},
{'contents': 'bar', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True, 'highlight_group': ['cwd:current_folder', 'cwd']},
])
segment_info['home'] = '/abc/def/ghi'
self.assertEqual(shell.cwd(pl=pl, segment_info=segment_info), [
{'contents': '~', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True},
{'contents': 'foo', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True},
{'contents': 'bar', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True, 'highlight_group': ['cwd:current_folder', 'cwd']},
])
segment_info.update(shortened_path='~foo/ghi')
self.assertEqual(shell.cwd(pl=pl, segment_info=segment_info), [
{'contents': '~foo', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True},
{'contents': 'ghi', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True, 'highlight_group': ['cwd:current_folder', 'cwd']},
])
self.assertEqual(shell.cwd(pl=pl, segment_info=segment_info, use_shortened_path=False), [
{'contents': '~', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True},
{'contents': 'foo', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True},
{'contents': 'bar', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True, 'highlight_group': ['cwd:current_folder', 'cwd']},
])
segment_info.pop('shortened_path')
self.assertEqual(shell.cwd(pl=pl, segment_info=segment_info, dir_limit_depth=3), [
{'contents': '~', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True},
{'contents': 'foo', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True},
{'contents': 'bar', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True, 'highlight_group': ['cwd:current_folder', 'cwd']}
])
self.assertEqual(shell.cwd(pl=pl, segment_info=segment_info, dir_limit_depth=3, shorten_home=False), [
{'contents': '', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True},
{'contents': 'ghi', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True},
{'contents': 'foo', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True},
{'contents': 'bar', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True, 'highlight_group': ['cwd:current_folder', 'cwd']}
])
self.assertEqual(shell.cwd(pl=pl, segment_info=segment_info, dir_limit_depth=1), [
{'contents': '', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True},
{'contents': 'bar', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True, 'highlight_group': ['cwd:current_folder', 'cwd']}
])
self.assertEqual(shell.cwd(pl=pl, segment_info=segment_info, dir_limit_depth=1, ellipsis='...'), [
{'contents': '...', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True},
{'contents': 'bar', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True, 'highlight_group': ['cwd:current_folder', 'cwd']}
])
self.assertEqual(shell.cwd(pl=pl, segment_info=segment_info, dir_limit_depth=1, ellipsis=None), [
{'contents': 'bar', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True, 'highlight_group': ['cwd:current_folder', 'cwd']}
])
self.assertEqual(shell.cwd(pl=pl, segment_info=segment_info, dir_limit_depth=1, use_path_separator=True), [
{'contents': '⋯/', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': False},
{'contents': 'bar', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': False, 'highlight_group': ['cwd:current_folder', 'cwd']}
])
self.assertEqual(shell.cwd(pl=pl, segment_info=segment_info, dir_limit_depth=1, use_path_separator=True, ellipsis='...'), [
{'contents': '.../', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': False},
{'contents': 'bar', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': False, 'highlight_group': ['cwd:current_folder', 'cwd']}
])
self.assertEqual(shell.cwd(pl=pl, segment_info=segment_info, dir_limit_depth=1, use_path_separator=True, ellipsis=None), [
{'contents': 'bar', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': False, 'highlight_group': ['cwd:current_folder', 'cwd']}
])
self.assertEqual(shell.cwd(pl=pl, segment_info=segment_info, dir_limit_depth=2, dir_shorten_len=2), [
{'contents': '~', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True},
{'contents': 'fo', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True},
{'contents': 'bar', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True, 'highlight_group': ['cwd:current_folder', 'cwd']}
])
self.assertEqual(shell.cwd(pl=pl, segment_info=segment_info, dir_limit_depth=2, dir_shorten_len=2, use_path_separator=True), [
{'contents': '~/', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': False},
{'contents': 'fo/', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': False},
{'contents': 'bar', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': False, 'highlight_group': ['cwd:current_folder', 'cwd']}
])
cwd[0] = '/etc'
self.assertEqual(shell.cwd(pl=pl, segment_info=segment_info, use_path_separator=False), [
{'contents': '/', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True},
{'contents': 'etc', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True, 'highlight_group': ['cwd:current_folder', 'cwd']},
])
self.assertEqual(shell.cwd(pl=pl, segment_info=segment_info, use_path_separator=True), [
{'contents': '/', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': False},
{'contents': 'etc', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': False, 'highlight_group': ['cwd:current_folder', 'cwd']},
])
cwd[0] = '/'
self.assertEqual(shell.cwd(pl=pl, segment_info=segment_info, use_path_separator=False), [
{'contents': '/', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True, 'highlight_group': ['cwd:current_folder', 'cwd']},
])
self.assertEqual(shell.cwd(pl=pl, segment_info=segment_info, use_path_separator=True), [
{'contents': '/', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': False, 'highlight_group': ['cwd:current_folder', 'cwd']},
])
ose = OSError()
ose.errno = 2
cwd[0] = ose
self.assertEqual(shell.cwd(pl=pl, segment_info=segment_info, dir_limit_depth=2, dir_shorten_len=2), [
{'contents': '[not found]', 'divider_highlight_group': 'cwd:divider', 'highlight_group': ['cwd:current_folder', 'cwd'], 'draw_inner_divider': True}
])
cwd[0] = OSError()
self.assertRaises(OSError, shell.cwd, pl=pl, segment_info=segment_info, dir_limit_depth=2, dir_shorten_len=2)
cwd[0] = ValueError()
self.assertRaises(ValueError, shell.cwd, pl=pl, segment_info=segment_info, dir_limit_depth=2, dir_shorten_len=2)
def test_date(self):
pl = Pl()
with replace_attr(common, 'datetime', Args(now=lambda: Args(strftime=lambda fmt: fmt))):
self.assertEqual(common.date(pl=pl), [{'contents': '%Y-%m-%d', 'highlight_group': ['date'], 'divider_highlight_group': None}])
self.assertEqual(common.date(pl=pl, format='%H:%M', istime=True), [{'contents': '%H:%M', 'highlight_group': ['time', 'date'], 'divider_highlight_group': 'time:divider'}])
class TestCommon(TestCase): class TestCommon(TestCase):
def test_hostname(self): def test_hostname(self):
@ -277,6 +393,12 @@ class TestCommon(TestCase):
{'contents': 'foo', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True}, {'contents': 'foo', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True},
{'contents': 'bar', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True, 'highlight_group': ['cwd:current_folder', 'cwd']} {'contents': 'bar', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True, 'highlight_group': ['cwd:current_folder', 'cwd']}
]) ])
self.assertEqual(common.cwd(pl=pl, segment_info=segment_info, dir_limit_depth=3, shorten_home=False), [
{'contents': '', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True},
{'contents': 'ghi', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True},
{'contents': 'foo', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True},
{'contents': 'bar', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True, 'highlight_group': ['cwd:current_folder', 'cwd']}
])
self.assertEqual(common.cwd(pl=pl, segment_info=segment_info, dir_limit_depth=1), [ self.assertEqual(common.cwd(pl=pl, segment_info=segment_info, dir_limit_depth=1), [
{'contents': '', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True}, {'contents': '', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True},
{'contents': 'bar', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True, 'highlight_group': ['cwd:current_folder', 'cwd']} {'contents': 'bar', 'divider_highlight_group': 'cwd:divider', 'draw_inner_divider': True, 'highlight_group': ['cwd:current_folder', 'cwd']}

View File

@ -39,5 +39,7 @@ do
break break
done done
1 1
hash -d foo=$PWD:h ; cd .
true
true is the last line true is the last line
exit exit

View File

@ -255,7 +255,7 @@ if test -z "${ONLY_SHELL}" || test "x${ONLY_SHELL%sh}" != "x${ONLY_SHELL}" || te
for POWERLINE_COMMAND in \ for POWERLINE_COMMAND in \
$PWD/scripts/powerline \ $PWD/scripts/powerline \
$PWD/scripts/powerline-render \ $PWD/scripts/powerline-render \
"$PYTHON $PWD/client/powerline.py" \ $PWD/client/powerline.py \
$PWD/client/powerline.sh $PWD/client/powerline.sh
do do
case "$POWERLINE_COMMAND" in case "$POWERLINE_COMMAND" in

Binary file not shown.

View File

@ -33,3 +33,5 @@ abc
1) def 2) ghi 3) jkl 1) def 2) ghi 3) jkl
 Select variant  1  Select variant  1
def def
 INSERT  ⋯  tests  shell  3rd  hash -d foo=$PWD:h ; cd .
 INSERT  ~foo  3rd  true