diff --git a/powerline/segments/common.py b/powerline/segments/common.py index 4a858d5b..5eda22ca 100644 --- a/powerline/segments/common.py +++ b/powerline/segments/common.py @@ -591,9 +591,12 @@ username = False _geteuid = getattr(os, 'geteuid', lambda: 1) -def user(pl, segment_info=None): +def user(pl, segment_info=None, hide_user=None): '''Return the current user. + :param str hide_user: + will suppress display of username if it matches the given string + Highlights the user with the ``superuser`` if the effective user ID is 0. Highlight groups used: ``superuser`` or ``user``. It is recommended to define all highlight groups. @@ -604,6 +607,8 @@ def user(pl, segment_info=None): if username is None: pl.warn('Failed to get username') return None + if username == hide_user: + return None euid = _geteuid() return [{ 'contents': username, diff --git a/tests/test_segments.py b/tests/test_segments.py index fea6e55d..03767749 100644 --- a/tests/test_segments.py +++ b/tests/test_segments.py @@ -80,6 +80,10 @@ class TestCommon(TestCase): self.assertEqual(common.user(pl=pl, segment_info=segment_info), [ {'contents': 'def', 'highlight_group': 'user'} ]) + self.assertEqual(common.user(pl=pl, segment_info=segment_info, hide_user='abc'), [ + {'contents': 'def', 'highlight_group': 'user'} + ]) + self.assertEqual(common.user(pl=pl, segment_info=segment_info, hide_user='def'), None) with replace_attr(common, '_geteuid', lambda: 0): self.assertEqual(common.user(pl=pl, segment_info=segment_info), [ {'contents': 'def', 'highlight_group': ['superuser', 'user']}