Add exclude_domain option to hostname segment

Provides an option to return only the hostname if an fqdn is returned by
socket.gethostname()
This commit is contained in:
Matt Spaulding 2013-03-30 15:09:01 -07:00
parent bc7c5b784d
commit e03e864f69

View File

@ -18,14 +18,18 @@ from powerline.lib.humanize_bytes import humanize_bytes
from collections import namedtuple from collections import namedtuple
def hostname(pl, only_if_ssh=False): def hostname(pl, only_if_ssh=False, exclude_domain=False):
'''Return the current hostname. '''Return the current hostname.
:param bool only_if_ssh: :param bool only_if_ssh:
only return the hostname if currently in an SSH session only return the hostname if currently in an SSH session
:param bool exclude_domain:
return the hostname without domain if there is one
''' '''
if only_if_ssh and not pl.environ.get('SSH_CLIENT'): if only_if_ssh and not pl.environ.get('SSH_CLIENT'):
return None return None
if exclude_domain:
return socket.gethostname().split('.')[0]
return socket.gethostname() return socket.gethostname()