mirror of
https://github.com/eepykate/fet.sh.git
synced 2026-11-07 16:01:03 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3d0cc3be21 | ||
|
|
3521c02a54 | ||
|
|
5a9c664bfb | ||
|
|
5d432d2c67 | ||
|
|
ce53a54d4c | ||
|
|
34f2b4b0a1 | ||
|
|
eede5b7666 | ||
|
|
43152b2837 | ||
|
|
0d8ab196c4 | ||
|
|
ea9abc7ffb | ||
|
|
accf87f751 | ||
|
|
7d2097cf00 | ||
|
|
1a4ecf462b | ||
|
|
81d4666525 | ||
|
|
8b3af10779 | ||
|
|
4a7caeabe5 | ||
|
|
dc190ac7ac | ||
|
|
71afae542c | ||
|
|
33d1029e8b | ||
|
|
402217d114 | ||
|
|
293b388623 | ||
|
|
473ed6f54f | ||
|
|
5dd087585c | ||
|
|
0ac1b7d216 | ||
|
|
b7fbb8784f | ||
|
|
6374278cac | ||
|
|
ce60c65e85 | ||
|
|
5b0c166444 | ||
|
|
f139798f16 | ||
|
|
c158f06c4d | ||
|
|
0a43ea82f3 | ||
|
|
55931b3bdf | ||
|
|
8f4d1cd8da | ||
|
|
e377e92ee2 | ||
|
|
1f0adf29de | ||
|
|
2815feda67 | ||
|
|
16a223b6c9 | ||
|
|
4d6732246e | ||
|
|
c95bed41eb | ||
|
|
579e6b54fb | ||
|
|
205831ab61 | ||
|
|
8fa8da9b28 | ||
|
|
06b87fba25 | ||
|
|
b48988f214 | ||
|
|
4821da4d3b | ||
|
|
75b665e153 | ||
|
|
a0ee667546 | ||
|
|
acec5ad4c5 | ||
|
|
b89c509aca | ||
|
|
3df3b25355 | ||
|
|
9dd1b3d698 | ||
|
|
3d615c8c91 | ||
|
|
ee56d6eed3 | ||
|
|
8c30f4a730 | ||
|
|
d336d54e98 |
No files matched your search
@@ -1,8 +1,28 @@
|
|||||||
<h2 align="center">fet.sh</h1>
|
|
||||||
|
|
||||||
|
|
||||||
<div align="center">
|
<div align="center">
|
||||||
fetch written in POSIX shell with no external commands
|
<h1>fet.sh</h1>
|
||||||
|
a fetch written in POSIX shell with no external commands
|
||||||
<br>
|
<br>
|
||||||
<img src="screenshot.png" width="250px">
|
<img src="screenshot.png" width="250px">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
### Installing
|
||||||
|
**Arch:** [fet.sh-git](https://aur.archlinux.org/packages/fet.sh-git) (AUR)
|
||||||
|
**Gentoo:** [app-misc/fetsh](https://gpo.zugaina.org/Overlays/guru/app-misc/fetsh) (GURU overlay)
|
||||||
|
**KISS:** [fetsh](https://github.com/kisslinux/community/tree/master/community/fetsh) (Community)
|
||||||
|
**Nix:** [fet-sh](https://search.nixos.org/packages?show=fet-sh&query=fet-sh&channel=unstable) (nixpkgs-unstable)
|
||||||
|
Alternatively, copy `fet.sh` to somewhere in $PATH and mark it as executable (`chmod +x fet.sh`)
|
||||||
|
|
||||||
|
### Customization
|
||||||
|
`fet.sh` has a few basic configuration options using environment variables, for example:
|
||||||
|
```
|
||||||
|
$ info='n os wm sh n' fet.sh
|
||||||
|
```
|
||||||
|
Supported options are:
|
||||||
|
- `accent` (0-7)
|
||||||
|
- `info`
|
||||||
|
- `separator`
|
||||||
|
|
||||||
|
For less simple configuration I recommend editing the script, I tried to keep it simple.
|
||||||
|
|
||||||
|
### Known Issues
|
||||||
|
MacOS, BSD, and Android don't show much info.
|
||||||
@@ -1,127 +1,271 @@
|
|||||||
#!/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 --
|
||||||
|
eq() { # equals | [ a = b ] with globbing
|
||||||
## Terminal
|
case $1 in
|
||||||
while [ ! "$term" ]; do
|
$2) ;;
|
||||||
while IFS=': ' read -r key val; do
|
*) return 1;;
|
||||||
case $key in
|
|
||||||
PPid) ppid=$val; break;;
|
|
||||||
esac
|
|
||||||
done < "/proc/${ppid:-$PPID}/status"
|
|
||||||
|
|
||||||
read -r name < "/proc/$ppid/comm"
|
|
||||||
case $name in
|
|
||||||
*sh) ;;
|
|
||||||
"${0##*/}") ;;
|
|
||||||
*[Ll]ogin*|*init*) term=linux;;
|
|
||||||
*) term="$name";;
|
|
||||||
esac
|
esac
|
||||||
done
|
}
|
||||||
|
|
||||||
## WM/DE
|
## DE
|
||||||
if [ "$XDG_CURRENT_DESKTOP" ]; then
|
wm=$XDG_CURRENT_DESKTOP
|
||||||
wm="$XDG_CURRENT_DESKTOP"
|
[ "$wm" ] || wm=$DESKTOP_SESSION
|
||||||
elif [ "$DESKTOP_SESSION" ]; then
|
|
||||||
wm="$DESKTOP_SESSION"
|
|
||||||
elif [ "$DISPLAY" ]; then
|
|
||||||
for i in /proc/*/comm; do
|
|
||||||
read -r c < "$i"
|
|
||||||
case $c in
|
|
||||||
awesome|xmonad|qtile|i3*|*box*|*wm*) wm="$c"; break;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
## Distro
|
## Distro
|
||||||
. /etc/os-release # lol EZ
|
# freedesktop.org/software/systemd/man/os-release.html
|
||||||
|
# a common file that has variables about the distro
|
||||||
|
for os in /etc/os-release /usr/lib/os-release; do
|
||||||
|
# some POSIX shells exit when trying to source a file that doesn't exist
|
||||||
|
[ -f $os ] && . $os && break
|
||||||
|
done
|
||||||
|
|
||||||
## Memory
|
if [ -e /proc/$$/comm ]; then
|
||||||
while read -r line; do
|
## Terminal
|
||||||
case $line in
|
while [ ! "$term" ]; do
|
||||||
MemTotal*) mem="${line##*: }"; break;;
|
# loop over lines in /proc/pid/status until it reaches PPid
|
||||||
|
# then save that to a variable and exit the file
|
||||||
|
while read -r line; do
|
||||||
|
eq "$line" 'PPid*' && ppid=${line##*:?} && break
|
||||||
|
done < "/proc/${ppid:-$PPID}/status"
|
||||||
|
|
||||||
|
# Make sure not to do an infinite loop
|
||||||
|
[ "$pppid" = "$ppid" ] && break
|
||||||
|
pppid=$ppid
|
||||||
|
|
||||||
|
# get name of binary
|
||||||
|
read -r name < "/proc/$ppid/comm"
|
||||||
|
|
||||||
|
case $name in
|
||||||
|
*sh|"${0##*/}") ;; # skip shells
|
||||||
|
*[Ll]ogin*|*init*|*systemd*) break;; # exit when the top is reached
|
||||||
|
# anything else can be assumed to be the terminal
|
||||||
|
# this has the side affect of catching tmux, but tmux
|
||||||
|
# detaches from the terminal and therefore ignoring that
|
||||||
|
# will just make the init the term
|
||||||
|
*) term=$name
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
## WM/DE
|
||||||
|
[ ! "$wm" ] &&
|
||||||
|
# loop over all processes and check the binary name
|
||||||
|
for i in /proc/*/comm; do
|
||||||
|
read -r c < "$i"
|
||||||
|
case $c in
|
||||||
|
*bar*) ;;
|
||||||
|
awesome|xmonad*|qtile|sway|i3|[bfo]*box|*wm*) wm=${c%%-*}; break;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
## 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
|
||||||
|
eq "$line" 'MemTotal*' && set -- $line && break
|
||||||
|
done < /proc/meminfo
|
||||||
|
mem="$(( $2 / 1000 ))MB"
|
||||||
|
|
||||||
|
## Processor
|
||||||
|
while read -r line; do
|
||||||
|
case $line in
|
||||||
|
vendor_id*) vendor="${line##*: } ";;
|
||||||
|
model\ name*) cpu=${line##*: }; break;;
|
||||||
|
esac
|
||||||
|
done < /proc/cpuinfo
|
||||||
|
|
||||||
|
## Uptime
|
||||||
|
# the simple math is shamefully stolen from aosync
|
||||||
|
IFS=. read -r uptime _ < /proc/uptime
|
||||||
|
d=$((uptime / 60 / 60 / 24))
|
||||||
|
up=$(printf %02d:%02d $((uptime / 60 / 60 % 24)) $((uptime / 60 % 60)))
|
||||||
|
[ "$d" -gt 0 ] && up="${d}d $up"
|
||||||
|
|
||||||
|
## Kernel
|
||||||
|
read -r _ _ version _ < /proc/version
|
||||||
|
kernel=${version%%-*}
|
||||||
|
eq "$version" '*Microsoft*' && ID="fake $ID"
|
||||||
|
|
||||||
|
## Motherboard // laptop
|
||||||
|
read -r model < /sys/devices/virtual/dmi/id/product_name
|
||||||
|
# invalid model handling
|
||||||
|
case $model in
|
||||||
|
# alternate file with slightly different info
|
||||||
|
# on my laptop it has the device model (instead of 'hp notebook')
|
||||||
|
# on my desktop it has the extended motherboard model
|
||||||
|
'System '*|'Default '*)
|
||||||
|
read -r model < /sys/devices/virtual/dmi/id/board_name
|
||||||
esac
|
esac
|
||||||
done < /proc/meminfo
|
|
||||||
mem="${mem##* }"
|
|
||||||
mem="$(( ${mem%% *} / 1000 ))"
|
|
||||||
|
|
||||||
## Processor
|
## Packages
|
||||||
while read -r line; do
|
# clean environment, then make every file in the dir an argument,
|
||||||
case $line in
|
# then save the argument count to $pkgs
|
||||||
vendor_id*) vendor="${line##*: }";;
|
set --
|
||||||
model\ name*) cpu="${line##*: }"; break;;
|
# kiss, arch, debian, void, gentoo
|
||||||
|
for i in '/var/db/kiss/installed/*' '/var/lib/pacman/local/[0-9a-z]*' \
|
||||||
|
'/var/lib/dpkg/info/*.list' '/var/db/xbps/.*' '/var/db/pkg/*/*'; do
|
||||||
|
set -- $i
|
||||||
|
[ $# -gt 1 ] && break
|
||||||
|
done
|
||||||
|
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
|
esac
|
||||||
done < /proc/cpuinfo
|
elif v=/System/Library/CoreServices/SystemVersion.plist; [ -f "$v" ]; then
|
||||||
vendor="${vendor##*Authentic}"
|
## Macos
|
||||||
vendor="${vendor##*Genuine}"
|
# make sure this variable is empty as to not break the following loop
|
||||||
# This is so messy due to so many inconsistencies in the model names
|
temp=
|
||||||
cpu="${cpu##*) }"
|
while read -r line; do
|
||||||
cpu="${cpu%% @*}"
|
case $line in
|
||||||
cpu="${cpu%% CPU}"
|
# set a variable so the script knows it's on the correct line
|
||||||
cpu="${cpu##CPU }"
|
# (the line after this one is the important one)
|
||||||
cpu="${cpu##*AMD }"
|
*ProductVersion*) temp=.;;
|
||||||
cpu="${cpu%% with*}"
|
*)
|
||||||
cpu="${cpu% *-Core*}"
|
# 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
|
||||||
|
|
||||||
## Uptime
|
eq "$0" '*fetish' && printf 'Step on me daddy\n' && exit
|
||||||
# the simple math is shamefully stolen from aosync
|
|
||||||
IFS=. read -r uptime _ < /proc/uptime
|
|
||||||
d=$((uptime / 60 / 60 / 24))
|
|
||||||
up=$(printf %02d:%02d $((uptime / 60 / 60 % 24)) $((uptime / 60 % 60)))
|
|
||||||
[ "$d" -gt 0 ] && up="${d}d $up"
|
|
||||||
|
|
||||||
## Kernel
|
# help i dont know if it's a capital consistently
|
||||||
read -r _ _ version _ < /proc/version
|
eq "$wm" '*[Gg][Nn][Oo][Mm][Ee]*' && wm='foot DE'
|
||||||
kernel="${version%%-*}"
|
|
||||||
case $version in
|
|
||||||
*Microsoft*) [ "$ID" ] && ID="fake $ID";;
|
|
||||||
esac
|
|
||||||
|
|
||||||
## GTK
|
## GTK
|
||||||
while read -r line; do
|
while read -r line; do
|
||||||
case $line in
|
eq "$line" 'gtk-theme*' && gtk=${line##*=} && break
|
||||||
gtk-theme*) gtk="${line##*=}"; break;;
|
done < "${XDG_CONFIG_HOME:=$HOME/.config}/gtk-3.0/settings.ini"
|
||||||
esac
|
|
||||||
done < "${XDG_CONFIG_HOME:-$HOME/.config}"/gtk-3.0/settings.ini
|
|
||||||
|
|
||||||
## Motherboard // laptop
|
# Shorten $cpu and $vendor
|
||||||
read -r model < /sys/devices/virtual/dmi/id/product_name
|
# 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*}
|
||||||
|
cpu=${cpu% *-Core*}
|
||||||
|
|
||||||
## Packages
|
col() {
|
||||||
[ -d /var/lib/pacman/local ] && set -- /var/lib/pacman/local/*
|
printf ' '
|
||||||
[ -d /var/db/xbps ] && set -- /var/db/xbps/.*
|
for i in 1 2 3 4 5 6; do
|
||||||
[ -d /var/db/pkg ] && set -- /var/db/pkg/*/*
|
printf '\033[9%sm▅▅' "$i"
|
||||||
[ $# -gt 0 ] && pkgs=$#
|
done
|
||||||
|
printf '\033[0m\n'
|
||||||
print() {
|
|
||||||
[ "$2" ] && printf '\033[3%sm%6s\033[0m ~ %s\n' "${accent:-4}" "$1" "$2"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print() {
|
||||||
|
[ "$2" ] && printf '\033[9%sm%6s\033[0m%b%s\n' \
|
||||||
|
"${accent:-4}" "$1" "${separator:- ~ }" "$2"
|
||||||
|
}
|
||||||
|
|
||||||
echo
|
# default value
|
||||||
read -r host < /etc/hostname
|
: "${info:=n user os sh wm up gtk cpu mem host kern pkgs term col n}"
|
||||||
printf '%7s@%s\n' "$USER" "$host"
|
|
||||||
|
|
||||||
print os "$ID"
|
for i in $info; do
|
||||||
print sh "${SHELL##*/}"
|
case $i in
|
||||||
print wm "$wm"
|
n) echo;;
|
||||||
print up "$up"
|
os) print os "$ID";;
|
||||||
print gtk "${gtk# }"
|
sh) print sh "${SHELL##*/}";;
|
||||||
print cpu "$vendor $cpu"
|
wm) print wm "${wm##*/}";;
|
||||||
print mem "${mem}MB"
|
up) print up "$up";;
|
||||||
print host "$model"
|
gtk) print gtk "${gtk# }";;
|
||||||
print kern "$kernel"
|
cpu) print cpu "$vendor$cpu";;
|
||||||
print pkgs "$pkgs"
|
mem) print mem "$mem";;
|
||||||
print term "$term"
|
host) print host "$model";;
|
||||||
|
kern) print kern "$kernel";;
|
||||||
printf ' '
|
pkgs) print pkgs "$pkgs";;
|
||||||
for i in 1 2 3 4 5 6; do
|
term) print term "$term";;
|
||||||
printf '\033[9%sm▅▅' "$i"
|
user) printf '%7s@%s\n' "$USER" "$host";;
|
||||||
|
col) col;;
|
||||||
|
esac
|
||||||
done
|
done
|
||||||
printf '\033[0m\n\n'
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 141 KiB |
Reference in new issue
Block a user