project: init

hello world
This commit is contained in:
Artur Manuel 2024-08-03 21:15:13 +01:00
commit 8e9d7016e8
Failed to generate hash of commit
9 changed files with 494 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
**/*.*~
/dist/

32
README.md Normal file
View file

@ -0,0 +1,32 @@
### whyfetch? 🤔
###### a fetch script that makes you ask why
---
### why whyfetch?
As per tradition when making new dotfiles (as well as the reason why norshfetch and norfetch were archived)
I usually create my own fetch script to accompany it. In this case I created a new rice involving Rose Pine which means my other scripts are as such outdated.
Especially since they call Linux-only functions. which is abhorrently cringe looking back.
### installing (with nix)
You can install this program by running the following in your command line.
```shell
% nix profile install "github:amadalusia/whyfetch#whyfetch"
```
However if you want to install it to your NixOS configuration (particularly with the help of flakes), [you can consume the overlay provided by the flake.](https://wiki.nixos.org/wiki/Overlays#In_NixOS)
### installing
~~[Download Nix](https://nixos.org/download/) and then follow the instructions above.~~
If you want to install the program then the following instructions below will get you there.
```shell
% poetry build
```
This will give you the `.whl` needed to run `pip install` on in the `dist/` directory.

175
flake.lock generated Normal file
View file

@ -0,0 +1,175 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1710146030,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_2": {
"inputs": {
"systems": "systems_2"
},
"locked": {
"lastModified": 1710146030,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nix-github-actions": {
"inputs": {
"nixpkgs": [
"poetry2nix",
"nixpkgs"
]
},
"locked": {
"lastModified": 1703863825,
"narHash": "sha256-rXwqjtwiGKJheXB43ybM8NwWB8rO2dSRrEqes0S7F5Y=",
"owner": "nix-community",
"repo": "nix-github-actions",
"rev": "5163432afc817cf8bd1f031418d1869e4c9d5547",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nix-github-actions",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1722495206,
"narHash": "sha256-kJ/MgnoLxuVVnGcVrnZuzZ2eUasKhD7SJG/HI8ugWVQ=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "43c433f2931b803dbe7853e0438ea0744ee48574",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable-small",
"repo": "nixpkgs",
"type": "github"
}
},
"poetry2nix": {
"inputs": {
"flake-utils": "flake-utils_2",
"nix-github-actions": "nix-github-actions",
"nixpkgs": [
"nixpkgs"
],
"systems": "systems_3",
"treefmt-nix": "treefmt-nix"
},
"locked": {
"lastModified": 1722515463,
"narHash": "sha256-6FVPz1WzHak65xJQg8tRjVyFEWMesGxfskKaCxDUnRk=",
"owner": "nix-community",
"repo": "poetry2nix",
"rev": "8c25e871bba3f472e1569bbf6c0f52dcc34bf2a4",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "poetry2nix",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs",
"poetry2nix": "poetry2nix"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"systems_2": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"systems_3": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"id": "systems",
"type": "indirect"
}
},
"treefmt-nix": {
"inputs": {
"nixpkgs": [
"poetry2nix",
"nixpkgs"
]
},
"locked": {
"lastModified": 1719749022,
"narHash": "sha256-ddPKHcqaKCIFSFc/cvxS14goUhCOAwsM1PbMr0ZtHMg=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "8df5ff62195d4e67e2264df0b7f5e8c9995fd0bd",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

56
flake.nix Normal file
View file

@ -0,0 +1,56 @@
{
description = "Application packaged using poetry2nix";
inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable-small";
poetry2nix = {
url = "github:nix-community/poetry2nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, flake-utils, poetry2nix }:
flake-utils.lib.eachDefaultSystem (system:
let
# see https://github.com/nix-community/poetry2nix/tree/master#api for more functions and examples.
pkgs = nixpkgs.legacyPackages.${system};
inherit (poetry2nix.lib.mkPoetry2Nix { inherit pkgs; }) mkPoetryApplication;
in
{
packages = {
whyfetch = mkPoetryApplication { projectDir = self; };
default = self.packages.${system}.whyfetch;
};
# Shell for app dependencies.
#
# nix develop
#
# Use this shell for developing your app.
devShells.default = pkgs.mkShell {
inputsFrom = [ self.packages.${system}.whyfetch ];
};
apps = {
whyfetch = {
program = "${self.packages.${system}.whyfetch}/bin/whyfetch";
type = "app";
};
default = {
program = "${self.packages.${system}.default}/bin/whyfetch";
type = "app";
};
};
# Shell for poetry.
#
# nix develop .#poetry
#
# Use this shell for changes to pyproject.toml and poetry.lock.
devShells.poetry = pkgs.mkShell {
nativeBuildInputs = [ pkgs.poetry ];
};
});
}

46
poetry.lock generated Normal file
View file

@ -0,0 +1,46 @@
# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand.
[[package]]
name = "psutil"
version = "6.0.0"
description = "Cross-platform lib for process and system monitoring in Python."
optional = false
python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,>=2.7"
files = [
{file = "psutil-6.0.0-cp27-cp27m-macosx_10_9_x86_64.whl", hash = "sha256:a021da3e881cd935e64a3d0a20983bda0bb4cf80e4f74fa9bfcb1bc5785360c6"},
{file = "psutil-6.0.0-cp27-cp27m-manylinux2010_i686.whl", hash = "sha256:1287c2b95f1c0a364d23bc6f2ea2365a8d4d9b726a3be7294296ff7ba97c17f0"},
{file = "psutil-6.0.0-cp27-cp27m-manylinux2010_x86_64.whl", hash = "sha256:a9a3dbfb4de4f18174528d87cc352d1f788b7496991cca33c6996f40c9e3c92c"},
{file = "psutil-6.0.0-cp27-cp27mu-manylinux2010_i686.whl", hash = "sha256:6ec7588fb3ddaec7344a825afe298db83fe01bfaaab39155fa84cf1c0d6b13c3"},
{file = "psutil-6.0.0-cp27-cp27mu-manylinux2010_x86_64.whl", hash = "sha256:1e7c870afcb7d91fdea2b37c24aeb08f98b6d67257a5cb0a8bc3ac68d0f1a68c"},
{file = "psutil-6.0.0-cp27-none-win32.whl", hash = "sha256:02b69001f44cc73c1c5279d02b30a817e339ceb258ad75997325e0e6169d8b35"},
{file = "psutil-6.0.0-cp27-none-win_amd64.whl", hash = "sha256:21f1fb635deccd510f69f485b87433460a603919b45e2a324ad65b0cc74f8fb1"},
{file = "psutil-6.0.0-cp36-abi3-macosx_10_9_x86_64.whl", hash = "sha256:c588a7e9b1173b6e866756dde596fd4cad94f9399daf99ad8c3258b3cb2b47a0"},
{file = "psutil-6.0.0-cp36-abi3-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:6ed2440ada7ef7d0d608f20ad89a04ec47d2d3ab7190896cd62ca5fc4fe08bf0"},
{file = "psutil-6.0.0-cp36-abi3-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:5fd9a97c8e94059b0ef54a7d4baf13b405011176c3b6ff257c247cae0d560ecd"},
{file = "psutil-6.0.0-cp36-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e2e8d0054fc88153ca0544f5c4d554d42e33df2e009c4ff42284ac9ebdef4132"},
{file = "psutil-6.0.0-cp36-cp36m-win32.whl", hash = "sha256:fc8c9510cde0146432bbdb433322861ee8c3efbf8589865c8bf8d21cb30c4d14"},
{file = "psutil-6.0.0-cp36-cp36m-win_amd64.whl", hash = "sha256:34859b8d8f423b86e4385ff3665d3f4d94be3cdf48221fbe476e883514fdb71c"},
{file = "psutil-6.0.0-cp37-abi3-win32.whl", hash = "sha256:a495580d6bae27291324fe60cea0b5a7c23fa36a7cd35035a16d93bdcf076b9d"},
{file = "psutil-6.0.0-cp37-abi3-win_amd64.whl", hash = "sha256:33ea5e1c975250a720b3a6609c490db40dae5d83a4eb315170c4fe0d8b1f34b3"},
{file = "psutil-6.0.0-cp38-abi3-macosx_11_0_arm64.whl", hash = "sha256:ffe7fc9b6b36beadc8c322f84e1caff51e8703b88eee1da46d1e3a6ae11b4fd0"},
{file = "psutil-6.0.0.tar.gz", hash = "sha256:8faae4f310b6d969fa26ca0545338b21f73c6b15db7c4a8d934a5482faa818f2"},
]
[package.extras]
test = ["enum34", "ipaddress", "mock", "pywin32", "wmi"]
[[package]]
name = "shellingham"
version = "1.5.4"
description = "Tool to Detect Surrounding Shell"
optional = false
python-versions = ">=3.7"
files = [
{file = "shellingham-1.5.4-py2.py3-none-any.whl", hash = "sha256:7ecfff8f2fd72616f7481040475a65b2bf8af90a56c89140852d1120324e8686"},
{file = "shellingham-1.5.4.tar.gz", hash = "sha256:8dbca0739d487e5bd35ab3ca4b36e11c4078f3a234bfce294b0a0291363404de"},
]
[metadata]
lock-version = "2.0"
python-versions = "^3.11"
content-hash = "26ad69ef918c0eb4f59054af91537705c4fe0849b000cfe8a6daae1647f9e09c"

20
pyproject.toml Normal file
View file

@ -0,0 +1,20 @@
[tool.poetry]
name = "whyfetch"
version = "0.1.0"
description = "if you dont want to use anything else then whyfetch?"
authors = ["Artur Manuel <balkenix@outlook.com>"]
license = "MIT"
readme = "README.md"
[tool.poetry.dependencies]
python = "^3.11"
psutil = "^6.0.0"
shellingham = "^1.5.4"
[tool.poetry.scripts]
whyfetch = "whyfetch:__main__"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

1
result Symbolic link
View file

@ -0,0 +1 @@
/nix/store/zl079m90ywjaknmk8imh33xxlp9qx63q-python3.12-whyfetch-0.1.0

44
whyfetch/__init__.py Normal file
View file

@ -0,0 +1,44 @@
import whyfetch.system_properties as w
colours = {
"red": "\x1b[1;31m",
"blue": "\x1b[1;34m",
"white": "\x1b[1;39m",
}
def separator_from_longest_prop(properties: list[w.Prop]):
j: int = 0
for i in properties:
if i.length > j:
j = i.length
continue
else:
continue
return ""*j
def __main__():
kernel: w.Kernel = w.Kernel()
ram: w.Ram = w.Ram()
username: w.Username = w.Username()
os: w.Os = w.Os()
shell: w.Shell = w.Shell()
uptime: w.Uptime = w.Uptime()
locale: w.Locale = w.Locale()
properties: list[w.Prop] = [ kernel.prop, ram.prop, username.prop, os.prop, uptime.prop, locale.prop ]
print(f'{colours["white"]}━━━━━━━━━━━━━━━{separator_from_longest_prop(properties)}')
print(f' {colours["red"]}_.----._{colours["white"]} {username.prop.content}@{kernel.node}')
print(f' {colours["red"]}.\' \'.{colours["white"]} {kernel.prop.content}')
print(f'{colours["red"]}/{colours["white"]}._ _.--._ {colours["red"]}}\\ {os.prop.content}')
print(f'|_ \'-\' _.._ `| {shell.prop.content}')
print(f'\\ `---\' `-/ {ram.prop.content}')
print(f' \'._ _.\' {uptime.prop.content}')
print(f' \'----\' {locale.prop.content}')
print(f'━━━━━━━━━━━━━━━{separator_from_longest_prop(properties)}')

View file

@ -0,0 +1,118 @@
import platform
import psutil
import os
from sys import platform as platform2
import csv
import pathlib
import shellingham as shelling
import time
import locale
from typing import Optional
uname = platform.uname()
svmem = psutil.virtual_memory()
b_to_mb = lambda s : int(s / pow(1024, 2))
class Prop:
def __init__(self, content) -> None:
self.content = content
self.length = len(self.content)
pass
# OOP brainrot
class Kernel:
def __init__(self) -> None:
self.system: str = uname.system
self.release: str = uname.release
self.machine: str = uname.machine
self.node: str = uname.node
self.prop: Prop = Prop(f"kernel: {self.system} {self.release} {self.machine}")
pass
class Ram:
def __init__(self) -> None:
self.total: int = svmem.total
self.used: int = svmem.used
self.available = svmem.available
self.prop: Prop = Prop(self.format())
pass
def format(self) -> str:
total_in_gb: int = b_to_mb(self.total)
used_in_gb: int = b_to_mb(self.used)
available_in_gb: int = b_to_mb(self.available)
return f"ram: {used_in_gb}MB/{total_in_gb}MB ({available_in_gb}MB free)"
class Username:
def __init__(self) -> None:
content: str = self.get_username()
self.prop: Prop = Prop(content)
pass
def get_username(self) -> str:
username: str = ""
user_home: str = os.path.expanduser('~')
if platform2 == "win32":
username = user_home.split("\\")[-1]
else:
username = user_home.split("/")[-1]
return username
class Os:
def __init__(self) -> None:
content: str = self.get_os_pretty_name()
self.prop: Prop = Prop(content)
pass
def get_os_pretty_name(self) -> str:
path = pathlib.Path("/etc/os-release")
with open(path) as stream:
reader = csv.reader(stream, delimiter="=")
os_release = dict(reader)
return f"os: {os_release['PRETTY_NAME']}"
class Shell:
def __init__(self) -> None:
content: str = self.get_shell()
self.prop: Prop = Prop(content)
pass
def get_shell(self) -> str:
try:
shell = shelling.detect_shell()
except shelling.shellDetectionFailure:
shell = self.provide_default()
return f"shell: {shell[0]}"
def provide_default():
if os.name == 'posix':
return os.environ['SHELL']
elif os.name == 'nt':
return os.environ['COMSPEC']
raise NotImplementedError(f'OS {os.name!r} support not available')
class Uptime:
def __init__(self) -> None:
content: str = f"up: {self.get_uptime()}"
self.prop = Prop(content)
pass
def get_uptime(self) -> str:
seconds_elapsed = time.time() - psutil.boot_time()
seconds: int = int(seconds_elapsed % 60)
minutes: int = int(seconds_elapsed / 60) % 60
hours: int = int(seconds_elapsed / pow(60, 2))
return f"{hours} hours, {minutes} minutes and {seconds} seconds"
class Locale:
def __init__(self) -> None:
content: str = f"locale: {locale.setlocale(locale.LC_CTYPE)}"
self.prop: Prop = Prop(content)
pass