class UserAtHost(Segment): bg = colors.background(theme.USERATHOST_BG) fg = colors.foreground(theme.USERATHOST_FG) def init(self): self.text = '{}@{}'.format(getpass.getuser(), socket.gethostname().replace('.local', ''))
def print_warning(text): from utils import colors from utils.glyphs import ESCLAMATION from segments.basics import Divider divider = Divider() cross_rendered = '{}{} {}{}{}{}'.format( colors.background(colors.GOLD), ESCLAMATION, colors.reset(), colors.foreground(colors.GOLD), divider.text if divider.active else '', colors.reset() ) text_rendered = '{}{}promptastic{}: {}{}\n'.format( colors.foreground(colors.LIGHTER_GOLD), colors.underline_start(), colors.underline_end(), text, colors.reset() ) output = '{} {}'.format(cross_rendered, text_rendered) print_raw(output)
class CurrentDir(Segment): bg = colors.background(theme.CURRENTDIR_BG) fg = colors.foreground(theme.CURRENTDIR_FG) def init(self, cwd): home = os.path.expanduser('~') self.text = cwd.replace(home, '~')
class Time(Segment): bg = colors.background(theme.TIME_BG) fg = colors.foreground(theme.TIME_FG) def init(self): now = datetime.now().time() self.text = '{} {}:{}:{}'.format(glyphs.TIME, now.hour, now.minute, now.second)
class ExitCode(Segment): bg = colors.background(theme.EXITCODE_BG) fg = colors.foreground(theme.EXITCODE_FG) def init(self): self.text = ' ' + glyphs.CROSS + ' ' if sys.argv[1] == '0': self.active = False
class ReadOnly(Segment): bg = colors.background(theme.READONLY_BG) fg = colors.foreground(theme.READONLY_FG) def init(self, cwd): self.text = ' ' + glyphs.WRITE_ONLY + ' ' if os.access(cwd, os.W_OK): self.active = False
class Ssh(Segment): bg = colors.background(theme.SSH_BG) fg = colors.foreground(theme.SSH_FG) + colors.bold() def init(self): self.text = 'SSH' if not os.getenv('SSH_CLIENT'): self.active = False
class Venv(Segment): bg = colors.background(theme.VENV_BG) fg = colors.foreground(theme.VENV_FG) def init(self): env = os.getenv('VIRTUAL_ENV') if env is None: self.active = False return env_name = os.path.basename(env) self.text = glyphs.VIRTUAL_ENV + ' ' + env_name
def init(self): branch_name = self.get_branch_name() if not branch_name: self.active = False return self.git_status_output = self.get_git_status_output() wd_glyph, git_colors = self.get_working_dir_status_decorations() self.bg = colors.background(git_colors[0]) self.fg = colors.foreground(git_colors[1]) current_commit_text = self.get_current_commit_decoration_text() self.text = wd_glyph + ' ' + branch_name + glyphs.BRANCH + ' ' + current_commit_text
class Jobs(Segment): bg = colors.background(theme.JOBS_BG) fg = colors.foreground(theme.JOBS_FG) def init(self): pppid = subprocess.Popen( ['ps', '-p', str(os.getppid()), '-oppid='], stdout=subprocess.PIPE).communicate()[0].strip() output = subprocess.Popen(['ps', '-a', '-o', 'ppid'], stdout=subprocess.PIPE).communicate()[0] num_jobs = len(re.findall(bytes(pppid), output)) - 1 self.text = '{} {}'.format(glyphs.HOURGLASS, num_jobs) if not num_jobs: self.active = False
def print_warning(text): from utils import colors from utils.glyphs import ESCLAMATION from segments.basics import Divider divider = Divider() cross_rendered = '{}{} {}{}{}{}'.format( colors.background(colors.GOLD), ESCLAMATION, colors.reset(), colors.foreground(colors.GOLD), divider.text if divider.active else '', colors.reset()) text_rendered = '{}{}promptastic{}: {}{}\n'.format( colors.foreground(colors.LIGHTER_GOLD), colors.underline_start(), colors.underline_end(), text, colors.reset()) output = '{} {}'.format(cross_rendered, text_rendered) print_raw(output)
class Padding(Segment): bg = colors.background(theme.PADDING_BG) def init(self, amount): self.text = ''.ljust(amount)
class Time(Segment): bg = colors.background(theme.TIME_BG) fg = colors.foreground(theme.TIME_FG) def init(self): self.text = glyphs.TIME + ' ' + str(time.strftime("%H:%M:%S"))
class Time(Segment): bg = colors.background(theme.TIME_BG) fg = colors.foreground(theme.TIME_FG) def init(self): self.text = '{} {}'.format(glyphs.TIME, time.strftime("%H:%M:%S"))