commit d68f9348332089a1b86095fa3506dfb6ca744232 Author: Gauge Krahe Date: Tue Jul 28 09:14:27 2020 +1000 init diff --git a/README.md b/README.md new file mode 100644 index 0000000..7d72c35 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +fetch written in POSIX shell with no external utilities diff --git a/posixfetch b/posixfetch new file mode 100755 index 0000000..df3436d --- /dev/null +++ b/posixfetch @@ -0,0 +1,54 @@ +#!/bin/sh +# +# this is my attempt at trying to make a fetch using only posix shell +# and as little if none external utilities as I can. +# + + +## Terminal +ppid() { + while read -r line; do + case $line in + PPid*) echo "${line##*:?}"; break;; + esac + done < /proc/"$1"/status +} + +while [ ! "$term" ]; do + read -r name < "/proc/${ppid:=$$}/comm" + case $name in + *sh) ;; + "${0##*/}") ;; + *[Ll]ogin*|*init*) term=linux;; + *) term="$name";; + esac + ppid=$(ppid "$ppid") +done + +## Distro +. /etc/os-release # lol EZ + +## Packages +# horribly inefficient, I know. +command -v pacman-key >/dev/null 2>&1 && { + pkgs=0 + for i in /var/lib/pacman/local/*; do + pkgs=$(( pkgs + 1 )) + done +} + +command -v xbps-install >/dev/null 2>&1 && { + pkgs=0 + for i in /var/db/xbps/*; do + pkgs=$(( pkgs + 1 )) + done +} + +print() { + printf '\033[38;05;16m%8s\033[0m | %s\n' "$1" "$2" +} + +print os "$ID" +print sh "${SHELL##*/}" +print term "$term" +[ "$pkgs" ] && print "pkgs" "$pkgs"