nearly a real fetch script
This commit is contained in:
parent
e6f13164a8
commit
5610ef62ef
71
fetchpy5
71
fetchpy5
@ -3,9 +3,10 @@
|
|||||||
# Ferit Yiğit BALABAN <fyb@fybx.dev>, 2024
|
# Ferit Yiğit BALABAN <fyb@fybx.dev>, 2024
|
||||||
#
|
#
|
||||||
# fetchpy, fetch script alternative to neofetch
|
# fetchpy, fetch script alternative to neofetch
|
||||||
# revision 5
|
# revision 6
|
||||||
import os
|
import os
|
||||||
from subprocess import run
|
import sys
|
||||||
|
import subprocess as sp
|
||||||
|
|
||||||
|
|
||||||
def print_pipeline(text):
|
def print_pipeline(text):
|
||||||
@ -67,28 +68,45 @@ def read_until_space(text, start_at):
|
|||||||
return buffer, next_space_at
|
return buffer, next_space_at
|
||||||
|
|
||||||
|
|
||||||
|
def find_username():
|
||||||
|
return sp.run(['whoami'], text=True, capture_output=True).stdout[0:-1]
|
||||||
|
|
||||||
|
|
||||||
|
def find_hostname():
|
||||||
|
return sp.run(['uname', '-n'], text=True, capture_output=True).stdout[0:-1]
|
||||||
|
|
||||||
|
|
||||||
|
def find_login_shell(username):
|
||||||
|
toGrep = sp.Popen(['cat', '/etc/passwd'], stdout=sp.PIPE)
|
||||||
|
toSplit = sp.check_output(('grep', f'{username}'), stdin=toGrep.stdout)
|
||||||
|
toGrep.wait()
|
||||||
|
return toSplit.decode(sys.stdout.encoding)[0:-1].split(':')[-1]
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
padding_count = 17
|
props = []
|
||||||
|
_username = find_username()
|
||||||
|
# _hostname = find_hostname()
|
||||||
|
_login_shell = find_login_shell(_username).split('/')[-1]
|
||||||
|
|
||||||
distro_name = 'Arch GNU+Linux'
|
props.append('Arch GNU+Linux') # distro_name
|
||||||
distro_name = distro_name.ljust(padding_count, ' ')
|
props.append(os.uname().release) #kernel_version
|
||||||
|
|
||||||
kernel_version = str(os.uname().release)
|
installed_packages = sp.run(['pacman', '-Q'], text=True, capture_output=True).stdout.splitlines()
|
||||||
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:
|
for _ in installed_packages:
|
||||||
if shell_name in _:
|
if _login_shell in _:
|
||||||
shell_name = _.removesuffix('\n').ljust(padding_count, ' ')
|
props.append(_.removesuffix('\n')) # shell_name
|
||||||
package_count = str(len(installed_packages)).ljust(padding_count, ' ')
|
|
||||||
|
props.append(str(len(installed_packages))) # package_count
|
||||||
|
|
||||||
total_mem, used_mem, _, _, _, _ = map(int, os.popen('free -m').readlines()[1].split()[1:])
|
total_mem, used_mem, _, _, _, _ = map(int, os.popen('free -m').readlines()[1].split()[1:])
|
||||||
def rnd(x): return round(x, 1)
|
def rnd(x): return round(x, 1)
|
||||||
mem_usage = f'{rnd(used_mem / 1024)} GB / {rnd(total_mem / 1024)} GB'.ljust(padding_count, ' ')
|
props.append(f'{rnd(used_mem / 1024)} GB / {rnd(total_mem / 1024)} GB') # mem_usage
|
||||||
|
|
||||||
with open('/proc/uptime', 'r', encoding='utf8') as file:
|
with open('/proc/uptime', 'r', encoding='utf8') as file:
|
||||||
uptime_seconds = float(file.readline().split()[0])
|
uptime_seconds = float(file.readline().split()[0])
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
if uptime_seconds < 60:
|
if uptime_seconds < 60:
|
||||||
uptime = str(uptime_seconds).split('.', maxsplit=1)[0] + ' seconds'
|
uptime = str(uptime_seconds).split('.', maxsplit=1)[0] + ' seconds'
|
||||||
elif uptime_seconds < 3600:
|
elif uptime_seconds < 3600:
|
||||||
@ -97,17 +115,24 @@ def main():
|
|||||||
else:
|
else:
|
||||||
number = str(uptime_seconds / 3600).split('.', maxsplit=1)[0]
|
number = str(uptime_seconds / 3600).split('.', maxsplit=1)[0]
|
||||||
uptime = f'{number} hour' if number == '1' else f'{number} hours'
|
uptime = f'{number} hour' if number == '1' else f'{number} hours'
|
||||||
uptime = uptime.ljust(padding_count, ' ')
|
props.append(uptime)
|
||||||
|
|
||||||
|
padding_count = 10
|
||||||
|
for prop in props:
|
||||||
|
if len(prop) > padding_count:
|
||||||
|
padding_count = len(prop) + 1
|
||||||
|
for i in range(0, len(props)):
|
||||||
|
props[i] = props[i].ljust(padding_count, ' ')
|
||||||
|
|
||||||
txt = \
|
txt = \
|
||||||
f""" . ╭──── ferit@navi ────╮
|
f""" . ╭───── ferit@navi ─────╮
|
||||||
/ \\ │ {distro_name}│
|
/ \\ │ {props[0]}│
|
||||||
/ \\ │ {kernel_version}│
|
/ \\ │ {props[1]}│
|
||||||
/^. \\ │ {shell_name}│
|
/^. \\ │ {props[2]}│
|
||||||
/ .-. \\ │ {package_count}│
|
/ .-. \\ │ {props[3]}│
|
||||||
/ ( ) _\\ │ {mem_usage}│
|
/ ( ) _\\ │ {props[4]}│
|
||||||
/ _.~ ~._^\\ │ {uptime}│
|
/ _.~ ~._^\\ │ {props[5]}│
|
||||||
/.^ ^.\\ ╰────────────────────╯
|
/.^ ^.\\ ╰──────────────────────╯
|
||||||
"""
|
"""
|
||||||
|
|
||||||
print_pipeline(txt)
|
print_pipeline(txt)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user