mirror of
https://github.com/powerline/powerline.git
synced 2025-07-24 06:15:41 +02:00
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
|
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()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user