From 1ff0df87ad7a4b93755404e5062d4be8a0ea26db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferit=20Yi=C4=9Fit=20BALABAN?= Date: Tue, 7 Jun 2022 15:27:06 +0300 Subject: [PATCH] Better fetcher: fetchpy2 --- fetchpy | 65 +++++++++++---------------- fetchpy2 | 133 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 159 insertions(+), 39 deletions(-) create mode 100755 fetchpy2 diff --git a/fetchpy b/fetchpy index d241c4f..a7b64b8 100755 --- a/fetchpy +++ b/fetchpy @@ -43,31 +43,16 @@ def coloring(text): '┤': frame, '│': frame, '├': frame, - 'DST': info, - 'KRN': info, - 'SHL': info, - 'PCK': info, - 'CPU': info, - 'GPU': info, - 'MEM': info, - 'UPT': info, - 'ferit@navi': title, + '': info, + '': info, + '': info, + '': info, + '': info, + '': info, + '': info, + '': info, + '─ferit@navi': title, 'Hardware': title, - 'O': COLOR1, - 'o': COLOR1, - ':': COLOR2, - ';': COLOR2, - '>': COLOR3, - ',': COLOR4, - '.:/': COLOR4, - '/': COLOR4, - '\\\\\\': COLOR4, - '\\': COLOR4, - ',,///;,': COLOR4, - '\';\\': COLOR4, - '\';\\\\': COLOR4, - ',;/': COLOR4, - '\'\'\\\\\\\\\\\'"': COLOR4 } c = Console() iterator = 0 @@ -145,23 +130,25 @@ def main(): uptime = f'{number} hour' if number == '1' else f'{number} hours' uptime = uptime.ljust(padding_count, ' ') - txt = f''' - - ╭──────── ferit@navi ────────╮ - │ DST {distro_name}│ - O O , │ KRN {kernel_version}│ - o o .:/ │ SHL {shell_name}│ - o ,,///;, ,;/ │ PCK {package_count}│ - o o)::::::;;/// ├───────── Hardware ─────────┤ - >::::::::;;\\\\\\ │ CPU AMD Ryzen 7 5800H │ - ''\\\\\\\\\\'" ';\\ │ GPU NV GeForce RTX3050 Ti │ - ';\\ │ MEM {memory_usage}│ - │ UPT {uptime}│ - ╰────────────────────────────╯ - + txt = f'''╭─────── ferit@navi ───────╮ +│  {distro_name}│ +│  {kernel_version}│ +│  {shell_name}│ +│  {package_count}│ +├──────── Hardware ────────┤ +│  AMD Ryzen 7 5800H │ +│  NV GeForce RTX3050 Ti │ +│  {memory_usage}│ +│  {uptime}│ +╰──────────────────────────╯ ''' - coloring(txt) + txt_padded = '' + img_width = 15 + for line in txt.splitlines(): + txt_padded += ((' ' * img_width) + line + '\n') + coloring(txt_padded) if __name__ == '__main__': main() + diff --git a/fetchpy2 b/fetchpy2 new file mode 100755 index 0000000..c3e5a02 --- /dev/null +++ b/fetchpy2 @@ -0,0 +1,133 @@ +#!/usr/bin/env python3 +# +# Ferit Yiğit BALABAN , 2022 +# +# fetchpy, fetch script alternative to neofetch +import os +from subprocess import run + + +IMG_LOC = '/home/ferit/sources/neco.png' + + +def clr(text): + dump = '\u001b[30m█\u001b[31m█\u001b[32m█\u001b[33m█\u001b[34m█\u001b[35m█\u001b[36m█\u001b[37m█' + frame = '\u001b[31m' + info = '\u001b[32m' + title = '\u001b[33m' + clr_dict = { + '╭': frame, + '╰': frame, + '╯': frame, + '─': frame, + '╮': frame, + '┤': frame, + '│': frame, + '├': frame, + '': info, + '': info, + '': info, + '': info, + '': info, + '': info, + '': info, + '': info, + 'ferit@navi': title, + 'Hardware': '', + } + iter = 0 + while iter < len(text): + char = text[iter] + peekable = iter < len(text) - 1 + peek = text[iter + 1] if peekable else ' ' + + if char == ' ': + if peekable and peek != ' ' and not clr_dict.__contains__(peek): + print(' ', end='') + word, jump_to = read_until_space(text, start_at=iter + 1) + if clr_dict.__contains__(word): + if word == 'Hardware': + print(dump, end='') + else: + print(f'{clr_dict[word]}{word}\u001b[0m', end='') + else: + print(word, end='') + iter = jump_to + print(' ', end='') + elif clr_dict.__contains__(char): + print(f'{clr_dict[char]}{char}\u001b[0m', end='') + else: + print(char, end='') + iter += 1 + print('') + + +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 = 23 + + 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_memory, used_memory, free_memory, d1, d2, d3 = map(int, os.popen('free -m').readlines()[1].split()[1:]) + memory_usage = f'{round((used_memory / 1024), 1)} GB / {round((total_memory / 1024), 1)} GB'.ljust(padding_count, ' ') + + with open('/proc/uptime', 'r') as f: + uptime_seconds = float(f.readline().split()[0]) + f.close() + if uptime_seconds < 60: + uptime = str(uptime_seconds).split('.')[0] + ' seconds' + elif uptime_seconds < 3600: + number = str(uptime_seconds / 60).split('.')[0] + uptime = f'{number} minute' if number == '1' else f'{number} minutes' + else: + number = str(uptime_seconds / 3600).split('.')[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}│ +├──────── Hardware ────────┤ +│  AMD Ryzen 7 5800H │ +│  NV GeForce RTX3050 Ti │ +│  {memory_usage}│ +│  {uptime}│ +╰──────────────────────────╯ +''' + + txt_padded = '' + img_width = 15 + line_count = 0 + for line in txt.splitlines(): + txt_padded += ((' ' * img_width) + line + '\n') + line_count += 1 + run(['/usr/bin/kitty', 'icat', '--align', 'left', IMG_LOC]) + run(['printf', "\e[%sA\e[999999D", str(line_count)]) + clr(txt_padded) + + +if __name__ == '__main__': + main() +