-
Notifications
You must be signed in to change notification settings - Fork 729
Expand file tree
/
Copy pathhostname.py
More file actions
29 lines (27 loc) · 1.13 KB
/
Copy pathhostname.py
File metadata and controls
29 lines (27 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import os
from ..utils import BasicSegment
from ..color_compliment import stringToHashToColorAndOpposite
from ..colortrans import rgb2short
from socket import gethostname
class Segment(BasicSegment):
def add_to_powerline(self):
powerline = self.powerline
if powerline.segment_conf("hostname", "only_on_ssh"):
if not os.getenv('SSH_CLIENT'):
return
if powerline.segment_conf("hostname", "colorize"):
hostname = gethostname()
FG, BG = stringToHashToColorAndOpposite(hostname)
FG, BG = (rgb2short(*color) for color in [FG, BG])
host_prompt = " %s " % hostname.split(".")[0]
powerline.append(host_prompt, FG, BG)
else:
if powerline.args.shell == "bash":
host_prompt = r" \h "
elif powerline.args.shell == "zsh":
host_prompt = " %m "
else:
host_prompt = " %s " % gethostname().split(".")[0]
powerline.append(host_prompt,
powerline.theme.HOSTNAME_FG,
powerline.theme.HOSTNAME_BG)