#!/usr/bin/env python3 # # Ferit Yiğit BALABAN , 2024 # # fetchpy, fetch script alternative to neofetch # revision 5 import os from subprocess import run def print_pipeline(text): stage1 = color_text(text) stage2 = color_art(stage1, 16) print(stage2) print('') def color_art(text, threshold): lines = text.splitlines() rebuilt = '' for line in lines: line = '\u001b[33m' + line[:threshold] + '\u001b[0m' + line[threshold:] rebuilt += (line + '\n') return rebuilt def color_text(text): output = '' frame = '\u001b[31m' info = '\u001b[32m' title = '\u001b[33m' clr_dict = {'╭': frame, '╰': frame, '╯': frame, '─': frame, '╮': frame, '│': frame, '': info, '': info, '': info, '': info, '': info, '󰢮': info, '': info, '': info, 'ferit@navi': title, 'Hardware': ''} i = 0 while i < len(text): char = text[i] peekable = i < len(text) - 1 peek = text[i + 1] if peekable else ' ' if char == ' ': if peekable and peek != ' ' and peek not in clr_dict: output += ' ' word, jump_to = read_until_space(text, start_at=i + 1) if word in clr_dict: output += f'{clr_dict[word]}{word}\u001b[0m' else: output += word i = jump_to output += ' ' elif char in clr_dict: output += f'{clr_dict[char]}{char}\u001b[0m' else: output += char i += 1 return output def read_until_space(text, start_at): buffer = '' iterator = start_at while text[iterator] != ' ': buffer += text[iterator] iterator += 1 next_space_at = iterator return buffer, next_space_at def main(): padding_count = 17 distro_name = 'Arch GNU+Linux' distro_name = distro_name.ljust(padding_count, ' ') kernel_version = str(os.uname().release) kernel_version = kernel_version.ljust(padding_count, ' ') installed_packages = run(['pacman', '-Q'], text=True, capture_output=True).stdout.splitlines() shell_name = 'fish' for _ in installed_packages: if shell_name in _: shell_name = _.removesuffix('\n').ljust(padding_count, ' ') package_count = str(len(installed_packages)).ljust(padding_count, ' ') total_mem, used_mem, _, _, _, _ = map(int, os.popen('free -m').readlines()[1].split()[1:]) def rnd(x): return round(x, 1) mem_usage = f'{rnd(used_mem / 1024)} GB / {rnd(total_mem / 1024)} GB'.ljust(padding_count, ' ') with open('/proc/uptime', 'r', encoding='utf8') as file: uptime_seconds = float(file.readline().split()[0]) file.close() if uptime_seconds < 60: uptime = str(uptime_seconds).split('.', maxsplit=1)[0] + ' seconds' elif uptime_seconds < 3600: number = str(uptime_seconds / 60).split('.', maxsplit=1)[0] uptime = f'{number} minute' if number == '1' else f'{number} minutes' else: number = str(uptime_seconds / 3600).split('.', maxsplit=1)[0] uptime = f'{number} hour' if number == '1' else f'{number} hours' uptime = uptime.ljust(padding_count, ' ') txt = \ f""" . ╭──── ferit@navi ────╮ / \\ │  {distro_name}│ / \\ │  {kernel_version}│ /^. \\ │  {shell_name}│ / .-. \\ │  {package_count}│ / ( ) _\\ │  {mem_usage}│ / _.~ ~._^\\ │  {uptime}│ /.^ ^.\\ ╰────────────────────╯ """ print_pipeline(txt) if __name__ == '__main__': main()