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:
parent
bc7c5b784d
commit
e03e864f69
|
@ -18,14 +18,18 @@ from powerline.lib.humanize_bytes import humanize_bytes
|
|||
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.
|
||||
|
||||
:param bool only_if_ssh:
|
||||
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'):
|
||||
return None
|
||||
if exclude_domain:
|
||||
return socket.gethostname().split('.')[0]
|
||||
return socket.gethostname()
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue