mirror of
https://github.com/eepykate/fet.sh.git
synced 2026-11-07 16:01:03 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c158f06c4d | ||
|
|
0a43ea82f3 | ||
|
|
1f0adf29de | ||
|
|
2815feda67 | ||
|
|
16a223b6c9 | ||
|
|
4d6732246e | ||
|
|
c95bed41eb | ||
|
|
579e6b54fb | ||
|
|
205831ab61 | ||
|
|
8fa8da9b28 | ||
|
|
06b87fba25 | ||
|
|
b48988f214 | ||
|
|
4821da4d3b |
No files matched your search
@@ -1,55 +1,63 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
#
|
#
|
||||||
# this is my attempt at trying to make a fetch using only posix shell
|
# fet.sh
|
||||||
# without any external commands
|
# a fetch in pure POSIX shell
|
||||||
#
|
#
|
||||||
|
|
||||||
# supress errors
|
# supress errors
|
||||||
exec 2>/dev/null
|
exec 2>/dev/null
|
||||||
set --
|
set --
|
||||||
|
_() { # [ a = b ] with globbing
|
||||||
|
case $1 in
|
||||||
|
$2) return
|
||||||
|
esac;! :
|
||||||
|
}
|
||||||
|
|
||||||
## Terminal
|
## Terminal
|
||||||
|
|
||||||
|
[ "$XDG_CURRENT_DESKTOP" ] && wm="$XDG_CURRENT_DESKTOP"
|
||||||
|
[ "$DESKTOP_SESSION" ] && wm="$DESKTOP_SESSION"
|
||||||
|
|
||||||
|
## Distro
|
||||||
|
o=/etc/os-release
|
||||||
|
[ -f $o ] && . $o # a common file that has variables about the distro
|
||||||
|
|
||||||
|
if [ -e /proc/$$/comm ]; then
|
||||||
while [ ! "$term" ]; do
|
while [ ! "$term" ]; do
|
||||||
while IFS=': ' read -r key val; do
|
# loop over lines in /proc/pid/status until it reaches PPid
|
||||||
case $key in
|
# then save that to a variable and exit the file
|
||||||
PPid) ppid=$val; break;;
|
while read -r line; do
|
||||||
esac
|
_ "$line" "PPid*" && ppid=${line##*:?} && break
|
||||||
done < "/proc/${ppid:-$PPID}/status"
|
done < "/proc/${ppid:-$PPID}/status"
|
||||||
|
|
||||||
|
# get name of binary
|
||||||
read -r name < "/proc/$ppid/comm"
|
read -r name < "/proc/$ppid/comm"
|
||||||
case $name in
|
case $name in
|
||||||
*sh) ;;
|
*sh|"${0##*/}"|tmux*) ;; # skip shells
|
||||||
"${0##*/}") ;;
|
*[Ll]ogin*|*init*) break;; # exit when the top is reached
|
||||||
*[Ll]ogin*|*init*) term=linux;;
|
*) term="$name" # anything else can be assumed to be the terminal
|
||||||
*) term="$name";;
|
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
## WM/DE
|
## WM/DE
|
||||||
if [ "$XDG_CURRENT_DESKTOP" ]; then
|
# standard variables, mostly used for DEs
|
||||||
wm="$XDG_CURRENT_DESKTOP"
|
[ "$DISPLAY" ] && [ ! "$wm" ] &&
|
||||||
elif [ "$DESKTOP_SESSION" ]; then
|
# non-standard WMs
|
||||||
wm="$DESKTOP_SESSION"
|
# loop over all processes and check the binary name
|
||||||
elif [ "$DISPLAY" ]; then
|
|
||||||
for i in /proc/*/comm; do
|
for i in /proc/*/comm; do
|
||||||
read -r c < "$i"
|
read -r c < "$i"
|
||||||
case $c in
|
case $c in
|
||||||
awesome|xmonad|qtile|i3*|*box*|*wm*) wm="$c"; break;;
|
awesome|xmonad|qtile|i3*|box*|*wm*) wm="$c"; break;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
fi
|
|
||||||
|
|
||||||
## Distro
|
|
||||||
. /etc/os-release # lol EZ
|
|
||||||
|
|
||||||
## Memory
|
## Memory
|
||||||
|
# loop over lines in /proc/meminfo until it reaches MemTotal,
|
||||||
|
# then convert the amount (second word) from KB to MB
|
||||||
while read -r line; do
|
while read -r line; do
|
||||||
case $line in
|
_ "$line" "MemTotal*" && set -- $line && break
|
||||||
MemTotal*) mem="${line##*: }"; break;;
|
|
||||||
esac
|
|
||||||
done < /proc/meminfo
|
done < /proc/meminfo
|
||||||
mem="${mem##* }"
|
mem="$(( $2 / 1000 ))MB"
|
||||||
mem="$(( ${mem%% *} / 1000 ))"
|
|
||||||
|
|
||||||
## Processor
|
## Processor
|
||||||
while read -r line; do
|
while read -r line; do
|
||||||
@@ -58,16 +66,6 @@ while read -r line; do
|
|||||||
model\ name*) cpu="${line##*: }"; break;;
|
model\ name*) cpu="${line##*: }"; break;;
|
||||||
esac
|
esac
|
||||||
done < /proc/cpuinfo
|
done < /proc/cpuinfo
|
||||||
vendor="${vendor##*Authentic}"
|
|
||||||
vendor="${vendor##*Genuine}"
|
|
||||||
# This is so messy due to so many inconsistencies in the model names
|
|
||||||
cpu="${cpu##*) }"
|
|
||||||
cpu="${cpu%% @*}"
|
|
||||||
cpu="${cpu%% CPU}"
|
|
||||||
cpu="${cpu##CPU }"
|
|
||||||
cpu="${cpu##*AMD }"
|
|
||||||
cpu="${cpu%% with*}"
|
|
||||||
cpu="${cpu% *-Core*}"
|
|
||||||
|
|
||||||
## Uptime
|
## Uptime
|
||||||
# the simple math is shamefully stolen from aosync
|
# the simple math is shamefully stolen from aosync
|
||||||
@@ -79,25 +77,134 @@ up=$(printf %02d:%02d $((uptime / 60 / 60 % 24)) $((uptime / 60 % 60)))
|
|||||||
## Kernel
|
## Kernel
|
||||||
read -r _ _ version _ < /proc/version
|
read -r _ _ version _ < /proc/version
|
||||||
kernel="${version%%-*}"
|
kernel="${version%%-*}"
|
||||||
case $version in
|
_ "$version" "*Microsoft*" && ID="fake $ID"
|
||||||
*Microsoft*) [ "$ID" ] && ID="fake $ID";;
|
|
||||||
esac
|
|
||||||
|
|
||||||
## GTK
|
|
||||||
while read -r line; do
|
|
||||||
case $line in
|
|
||||||
gtk-theme*) gtk="${line##*=}"; break;;
|
|
||||||
esac
|
|
||||||
done < "${XDG_CONFIG_HOME:-$HOME/.config}"/gtk-3.0/settings.ini
|
|
||||||
|
|
||||||
## Motherboard // laptop
|
## Motherboard // laptop
|
||||||
read -r model < /sys/devices/virtual/dmi/id/product_name
|
read -r model < /sys/devices/virtual/dmi/id/product_name
|
||||||
|
|
||||||
## Packages
|
## Packages
|
||||||
|
# clean environment, then make every file in the dir an argument,
|
||||||
|
# then save the argument count to $pkgs
|
||||||
|
set --
|
||||||
|
[ -d /var/db/kiss/installed ] && set -- /var/db/kiss/installed/*
|
||||||
[ -d /var/lib/pacman/local ] && set -- /var/lib/pacman/local/*
|
[ -d /var/lib/pacman/local ] && set -- /var/lib/pacman/local/*
|
||||||
[ -d /var/db/xbps ] && set -- /var/db/xbps/.*
|
[ -d /var/db/xbps ] && set -- /var/db/xbps/.*
|
||||||
[ -d /var/db/pkg ] && set -- /var/db/pkg/*/*
|
[ -d /var/db/pkg ] && set -- /var/db/pkg/*/* # gentoo
|
||||||
[ $# -gt 0 ] && pkgs=$#
|
pkgs=${###0}
|
||||||
|
|
||||||
|
read -r host < /proc/sys/kernel/hostname
|
||||||
|
elif [ -f /var/run/dmesg.boot ]; then
|
||||||
|
# Both OpenBSD and FreeBSD use this file, however they're formatted differently
|
||||||
|
read -r bsd < /var/run/dmesg.boot
|
||||||
|
case $bsd in
|
||||||
|
Open*)
|
||||||
|
## OpenBSD cpu/mem/name
|
||||||
|
while read -r line; do
|
||||||
|
case $line in
|
||||||
|
"real mem"*)
|
||||||
|
# use the pre-formatted value which is in brackets
|
||||||
|
mem=${line##*\(}
|
||||||
|
mem=${mem%\)*}
|
||||||
|
;;
|
||||||
|
# set $cpu to everything before a comma and after the field name
|
||||||
|
cpu0:*)
|
||||||
|
cpu=${line#cpu0: }
|
||||||
|
# Remove excess info after the actual CPU name
|
||||||
|
cpu=${cpu%%,*}
|
||||||
|
# Set the CPU Manufacturer to the first word of the cpu
|
||||||
|
# variable [separated by '(' or ' ']
|
||||||
|
vendor=${cpu%%[\( ]*}
|
||||||
|
# We got all the info we want, stop reading
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
# First 2 words in the file are OpenBSD <version>
|
||||||
|
*) [ "$ID" ] || { set -- $line; ID="$1 $2"; }
|
||||||
|
esac
|
||||||
|
done < /var/run/dmesg.boot
|
||||||
|
[ -d /var/db/pkg ] && set -- /var/db/pkg/* && pkgs=$#
|
||||||
|
read -r host < /etc/myname
|
||||||
|
host=${host%.*}
|
||||||
|
;;
|
||||||
|
# Everything else, assume FreeBSD (first line is ---<<BOOT>> or something)
|
||||||
|
*)
|
||||||
|
# shellcheck source=/dev/null
|
||||||
|
. /etc/rc.conf
|
||||||
|
# shut shellcheck up without disabling the warning
|
||||||
|
host=${hostname:-}
|
||||||
|
|
||||||
|
while read -r line; do
|
||||||
|
case $line in
|
||||||
|
# Ignore useless lines at the top
|
||||||
|
-*|' '*) ;;
|
||||||
|
*trademark*) ;;
|
||||||
|
|
||||||
|
# os version
|
||||||
|
FreeBSD*)
|
||||||
|
# If the OS is already set, no need to set it again
|
||||||
|
[ "$ID" ] && continue
|
||||||
|
ID="${line%%-R*}"
|
||||||
|
;;
|
||||||
|
|
||||||
|
CPU:*)
|
||||||
|
cpu=${cpu#CPU: }
|
||||||
|
# Remove excess info from after the actual CPU name
|
||||||
|
cpu=${line%\(*}
|
||||||
|
;;
|
||||||
|
*Origin=*)
|
||||||
|
# CPU Manufacturer
|
||||||
|
vendor=${line#*Origin=\"}
|
||||||
|
vendor="${vendor%%\"*} "
|
||||||
|
;;
|
||||||
|
|
||||||
|
"real memory"*)
|
||||||
|
# Get the pre-formatted amount which is inside brackets
|
||||||
|
mem=${line##*\(}
|
||||||
|
mem=${mem%\)*}
|
||||||
|
# This appears to be the final thing we need from the file,
|
||||||
|
# no need to read it more.
|
||||||
|
break
|
||||||
|
esac
|
||||||
|
done < /var/run/dmesg.boot
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
elif v=/System/Library/CoreServices/SystemVersion.plist; [ -f "$v" ]; then
|
||||||
|
## Macos
|
||||||
|
# make sure this variable is empty as to not break the following loop
|
||||||
|
temp=
|
||||||
|
while read -r line; do
|
||||||
|
case $line in
|
||||||
|
# set a variable so the script knows it's on the correct line
|
||||||
|
# (the line after this one is the important one)
|
||||||
|
*ProductVersion*) temp=.;;
|
||||||
|
*)
|
||||||
|
# check if the script is reading the derired line, if not
|
||||||
|
# don't do anything
|
||||||
|
[ "$temp" ] || continue
|
||||||
|
# Remove everything before and including the first '>'
|
||||||
|
ID=${line#*>}
|
||||||
|
# Remove the other side of the XML tag, and insert the actual OS name
|
||||||
|
ID="MacOS ${ID%<*}"
|
||||||
|
# We got the info we want, end the loop.
|
||||||
|
break
|
||||||
|
esac
|
||||||
|
done < "$v"
|
||||||
|
fi
|
||||||
|
|
||||||
|
## GTK
|
||||||
|
while read -r line; do
|
||||||
|
_ "$line" "gtk-theme*" && gtk="${line##*=}" && break
|
||||||
|
done < "${XDG_CONFIG_HOME:=$HOME/.config}/gtk-3.0/settings.ini"
|
||||||
|
|
||||||
|
# Shorten $cpu and $vendor
|
||||||
|
# this is so messy due to so many inconsistencies in the model names
|
||||||
|
vendor="${vendor##*Authentic}"
|
||||||
|
vendor="${vendor##*Genuine}"
|
||||||
|
cpu="${cpu##*) }"
|
||||||
|
cpu="${cpu%% @*}"
|
||||||
|
cpu="${cpu%% CPU}"
|
||||||
|
cpu="${cpu##CPU }"
|
||||||
|
cpu="${cpu##*AMD }"
|
||||||
|
cpu="${cpu%% with*}"
|
||||||
|
|
||||||
col() {
|
col() {
|
||||||
printf ' '
|
printf ' '
|
||||||
@@ -112,9 +219,10 @@ print() {
|
|||||||
"${accent:-4}" "$1" "${separator:- ~ }" "$2"
|
"${accent:-4}" "$1" "${separator:- ~ }" "$2"
|
||||||
}
|
}
|
||||||
|
|
||||||
read -r host < /proc/sys/kernel/hostname
|
# default value
|
||||||
|
: "${info:=n user os sh wm up gtk cpu mem host kern pkgs term col n}"
|
||||||
|
|
||||||
for i in ${info:-n user os sh wm up gtk cpu mem host kern pkgs term col n}; do
|
for i in $info; do
|
||||||
case $i in
|
case $i in
|
||||||
n) echo;;
|
n) echo;;
|
||||||
os) print os "$ID";;
|
os) print os "$ID";;
|
||||||
@@ -122,8 +230,8 @@ for i in ${info:-n user os sh wm up gtk cpu mem host kern pkgs term col n}; do
|
|||||||
wm) print wm "$wm";;
|
wm) print wm "$wm";;
|
||||||
up) print up "$up";;
|
up) print up "$up";;
|
||||||
gtk) print gtk "${gtk# }";;
|
gtk) print gtk "${gtk# }";;
|
||||||
gpu) print cpu "$vendor $cpu";;
|
cpu) print cpu "$vendor$cpu";;
|
||||||
mem) print mem "${mem}MB";;
|
mem) print mem "$mem";;
|
||||||
host) print host "$model";;
|
host) print host "$model";;
|
||||||
kern) print kern "$kernel";;
|
kern) print kern "$kernel";;
|
||||||
pkgs) print pkgs "$pkgs";;
|
pkgs) print pkgs "$pkgs";;
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 141 KiB |
Reference in new issue
Block a user