Exemple #1
0
def user(pl, hide_user=None, hide_domain=False):
    '''Return the current user.

	:param str hide_user:
		Omit showing segment for users with names equal to this string.
	:param bool hide_domain:
		Drop domain component if it exists in a username (delimited by '@').

	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.
	'''
    global username
    if username is False:
        username = _get_user()
    if username is None:
        pl.warn('Failed to get username')
        return None
    if username == hide_user:
        return None
    if hide_domain:
        try:
            username = username[:username.index('@')]
        except ValueError:
            pass
    euid = _geteuid()
    return [{
        'contents':
        username,
        'highlight_groups': ['user'] if euid != 0 else ['superuser', 'user'],
    }]
Exemple #2
0
def user(pl, hide_user=None, hide_domain=False):
	'''Return the current user.

	:param str hide_user:
		Omit showing segment for users with names equal to this string.
	:param bool hide_domain:
		Drop domain component if it exists in a username (delimited by '@').

	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.
	'''
	global username
	if username is False:
		username = _get_user()
	if username is None:
		pl.warn('Failed to get username')
		return None
	if username == hide_user:
		return None
	if hide_domain:
		try:
			username = username[:username.index('@')]
		except ValueError:
			pass
	euid = _geteuid()
	return [{
		'contents': username,
		'highlight_groups': ['user'] if euid != 0 else ['superuser', 'user'],
	}]
Exemple #3
0
def user(pl, segment_info, hide_user=None, hide_domain=False):
	'''Return the current user.

	:param str hide_user:
		Omit showing segment for users with names equal to this string.
	:param bool hide_domain:
		Drop domain component if it exists in a username (delimited by '@').

	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.
	'''
	global username
	if (
		segment_info['environ'].get('_POWERLINE_RUNNING_SHELL_TESTS')
		== 'ee5bcdc6-b749-11e7-9456-50465d597777'
	):
		return 'user'
	if username is False:
		username = _get_user()
	if username is None:
		pl.warn('Failed to get username')
		return None
	if username == hide_user:
		return None
	if hide_domain:
		try:
			username = username[:username.index('@')]
		except ValueError:
			pass
	euid = _geteuid()
	return [{
		'contents': username,
		'highlight_groups': ['user'] if euid != 0 else ['superuser', 'user'],
	}]
Exemple #4
0
def user(pl, segment_info, hide_user=None, hide_domain=False):
    '''Return the current user.

	:param str hide_user:
		Omit showing segment for users with names equal to this string.
	:param bool hide_domain:
		Drop domain component if it exists in a username (delimited by '@').

	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.
	'''
    global username
    if (segment_info['environ'].get('_POWERLINE_RUNNING_SHELL_TESTS') ==
            'ee5bcdc6-b749-11e7-9456-50465d597777'):
        return 'user'
    if username is False:
        username = _get_user()
    if username is None:
        pl.warn('Failed to get username')
        return None
    if username == hide_user:
        return None
    if hide_domain:
        try:
            username = username[:username.index('@')]
        except ValueError:
            pass
    euid = _geteuid()
    return [{
        'contents':
        username,
        'highlight_groups': ['user'] if euid != 0 else ['superuser', 'user'],
    }]
Exemple #5
0
def user(pl, hide_user=None):
	'''Return the current user.

	:param str hide_user:
		Omit showing segment for users with names equal to this 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.
	'''
	global username
	if username is False:
		username = _get_user()
	if username is None:
		pl.warn('Failed to get username')
		return None
	if username == hide_user:
		return None
	euid = _geteuid()
	return [{
		'contents': username,
		'highlight_group': ['user'] if euid != 0 else ['superuser', 'user'],
	}]
Exemple #6
0
def user(pl, hide_user=None):
    '''Return the current user.

	:param str hide_user:
		Omit showing segment for users with names equal to this 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.
	'''
    global username
    if username is False:
        username = _get_user()
    if username is None:
        pl.warn('Failed to get username')
        return None
    if username == hide_user:
        return None
    euid = _geteuid()
    return [{
        'contents':
        username,
        'highlight_group': ['user'] if euid != 0 else ['superuser', 'user'],
    }]