mirror of
https://github.com/eepykate/fet.sh.git
synced 2026-11-07 16:01:03 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
205831ab61 | ||
|
|
8fa8da9b28 | ||
|
|
06b87fba25 | ||
|
|
b48988f214 | ||
|
|
4821da4d3b | ||
|
|
75b665e153 | ||
|
|
a0ee667546 | ||
|
|
acec5ad4c5 | ||
|
|
b89c509aca | ||
|
|
3df3b25355 | ||
|
|
9dd1b3d698 | ||
|
|
3d615c8c91 | ||
|
|
ee56d6eed3 | ||
|
|
8c30f4a730 | ||
|
|
d336d54e98 |
No files matched your search
@@ -1,8 +1,20 @@
|
|||||||
<h2 align="center">fet.sh</h1>
|
|
||||||
|
|
||||||
|
|
||||||
<div align="center">
|
<div align="center">
|
||||||
|
<h1>fet.sh</h1>
|
||||||
fetch written in POSIX shell with no external commands
|
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)
|
||||||
|
**Other Distros:** copy `fet.sh` to somewhere in $PATH
|
||||||
|
|
||||||
|
### Customization
|
||||||
|
`fet.sh` can be configured using environment variables, for example:
|
||||||
|
```
|
||||||
|
$ info='n os wm sh n' fet.sh
|
||||||
|
```
|
||||||
|
Supported options are:
|
||||||
|
- `accent` (0-7)
|
||||||
|
- `info`
|
||||||
|
- `separator`
|
||||||
@@ -1,36 +1,44 @@
|
|||||||
#!/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
|
||||||
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##*/}") ;; # 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
|
||||||
|
# standard variables, mostly used for DEs
|
||||||
if [ "$XDG_CURRENT_DESKTOP" ]; then
|
if [ "$XDG_CURRENT_DESKTOP" ]; then
|
||||||
wm="$XDG_CURRENT_DESKTOP"
|
wm="$XDG_CURRENT_DESKTOP"
|
||||||
elif [ "$DESKTOP_SESSION" ]; then
|
elif [ "$DESKTOP_SESSION" ]; then
|
||||||
wm="$DESKTOP_SESSION"
|
wm="$DESKTOP_SESSION"
|
||||||
elif [ "$DISPLAY" ]; then
|
elif [ "$DISPLAY" ]; then
|
||||||
|
# non-standard WMs
|
||||||
|
# loop over all processes and check the binary name
|
||||||
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
|
||||||
@@ -40,16 +48,15 @@ elif [ "$DISPLAY" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
## Distro
|
## Distro
|
||||||
. /etc/os-release # lol EZ
|
. /etc/os-release # a common file that has variables about the distro
|
||||||
|
|
||||||
## 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
|
||||||
@@ -60,7 +67,7 @@ while read -r line; do
|
|||||||
done < /proc/cpuinfo
|
done < /proc/cpuinfo
|
||||||
vendor="${vendor##*Authentic}"
|
vendor="${vendor##*Authentic}"
|
||||||
vendor="${vendor##*Genuine}"
|
vendor="${vendor##*Genuine}"
|
||||||
# This is so messy due to so many inconsistencies in the model names
|
# 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="${cpu%% CPU}"
|
||||||
@@ -79,49 +86,59 @@ 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
|
## GTK
|
||||||
while read -r line; do
|
while read -r line; do
|
||||||
case $line in
|
_ "$line" "gtk-theme*" && gtk="${line##*=}" && break
|
||||||
gtk-theme*) gtk="${line##*=}"; break;;
|
|
||||||
esac
|
|
||||||
done < "${XDG_CONFIG_HOME:-$HOME/.config}"/gtk-3.0/settings.ini
|
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=$#
|
[ $# -gt 0 ] && pkgs=$#
|
||||||
|
|
||||||
print() {
|
col() {
|
||||||
[ "$2" ] && printf '\033[3%sm%6s\033[0m ~ %s\n' "${accent:-4}" "$1" "$2"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
echo
|
|
||||||
read -r host < /etc/hostname
|
|
||||||
printf '%7s@%s\n' "$USER" "$host"
|
|
||||||
|
|
||||||
print os "$ID"
|
|
||||||
print sh "${SHELL##*/}"
|
|
||||||
print wm "$wm"
|
|
||||||
print up "$up"
|
|
||||||
print gtk "${gtk# }"
|
|
||||||
print cpu "$vendor $cpu"
|
|
||||||
print mem "${mem}MB"
|
|
||||||
print host "$model"
|
|
||||||
print kern "$kernel"
|
|
||||||
print pkgs "$pkgs"
|
|
||||||
print term "$term"
|
|
||||||
|
|
||||||
printf ' '
|
printf ' '
|
||||||
for i in 1 2 3 4 5 6; do
|
for i in 1 2 3 4 5 6; do
|
||||||
printf '\033[9%sm▅▅' "$i"
|
printf '\033[9%sm▅▅' "$i"
|
||||||
done
|
done
|
||||||
printf '\033[0m\n\n'
|
printf '\033[0m\n'
|
||||||
|
}
|
||||||
|
|
||||||
|
print() {
|
||||||
|
[ "$2" ] && printf '\033[9%sm%6s\033[0m%b%s\n' \
|
||||||
|
"${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; do
|
||||||
|
case $i in
|
||||||
|
n) echo;;
|
||||||
|
os) print os "$ID";;
|
||||||
|
sh) print sh "${SHELL##*/}";;
|
||||||
|
wm) print wm "$wm";;
|
||||||
|
up) print up "$up";;
|
||||||
|
gtk) print gtk "${gtk# }";;
|
||||||
|
cpu) print cpu "$vendor $cpu";;
|
||||||
|
mem) print mem "$mem";;
|
||||||
|
host) print host "$model";;
|
||||||
|
kern) print kern "$kernel";;
|
||||||
|
pkgs) print pkgs "$pkgs";;
|
||||||
|
term) print term "$term";;
|
||||||
|
user) printf '%7s@%s\n' "$USER" "$host";;
|
||||||
|
col) col;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
Reference in new issue
Block a user