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 |
No files matched your search
@@ -1,19 +1,19 @@
|
|||||||
<div align="center">
|
<div align="center">
|
||||||
<h1>fet.sh</h1>
|
<h1>fet.sh</h1>
|
||||||
fetch written in POSIX shell with no external commands
|
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
|
### Installing
|
||||||
**Arch:** [fet.sh-git](https://aur.archlinux.org/packages/fet.sh-git/) (AUR)
|
**Arch:** [fet.sh-git](https://aur.archlinux.org/packages/fet.sh-git) (AUR)
|
||||||
**Nix:** [fet-sh](https://search.nixos.org/packages?show=fet-sh&query=fet-sh&channel=unstable) (nixpkgs-unstable)
|
|
||||||
**Gentoo:** [app-misc/fetsh](https://gpo.zugaina.org/Overlays/guru/app-misc/fetsh) (GURU overlay)
|
**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)
|
**KISS:** [fetsh](https://github.com/kisslinux/community/tree/master/community/fetsh) (Community)
|
||||||
**Other Distros:** copy `fet.sh` to somewhere in $PATH
|
**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
|
### Customization
|
||||||
`fet.sh` can be configured using environment variables, for example:
|
`fet.sh` has a few basic configuration options using environment variables, for example:
|
||||||
```
|
```
|
||||||
$ info='n os wm sh n' fet.sh
|
$ info='n os wm sh n' fet.sh
|
||||||
```
|
```
|
||||||
@@ -21,3 +21,8 @@ Supported options are:
|
|||||||
- `accent` (0-7)
|
- `accent` (0-7)
|
||||||
- `info`
|
- `info`
|
||||||
- `separator`
|
- `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.
|
||||||
@@ -9,15 +9,14 @@ exec 2>/dev/null
|
|||||||
set --
|
set --
|
||||||
eq() { # equals | [ a = b ] with globbing
|
eq() { # equals | [ a = b ] with globbing
|
||||||
case $1 in
|
case $1 in
|
||||||
# if the second argument matches the first, exit normally
|
$2) ;;
|
||||||
$2) return
|
*) return 1;;
|
||||||
# if it doesn't match, reverse the output of `:`, which makes an error
|
esac
|
||||||
esac;! :
|
|
||||||
}
|
}
|
||||||
|
|
||||||
## DE
|
## DE
|
||||||
wm="$XDG_CURRENT_DESKTOP"
|
wm=$XDG_CURRENT_DESKTOP
|
||||||
[ "$wm" ] || wm="$DESKTOP_SESSION"
|
[ "$wm" ] || wm=$DESKTOP_SESSION
|
||||||
|
|
||||||
## Distro
|
## Distro
|
||||||
# freedesktop.org/software/systemd/man/os-release.html
|
# freedesktop.org/software/systemd/man/os-release.html
|
||||||
@@ -33,20 +32,24 @@ if [ -e /proc/$$/comm ]; then
|
|||||||
# loop over lines in /proc/pid/status until it reaches PPid
|
# loop over lines in /proc/pid/status until it reaches PPid
|
||||||
# then save that to a variable and exit the file
|
# then save that to a variable and exit the file
|
||||||
while read -r line; do
|
while read -r line; do
|
||||||
eq "$line" "PPid*" && ppid=${line##*:?} && break
|
eq "$line" 'PPid*' && ppid=${line##*:?} && break
|
||||||
done < "/proc/${ppid:-$PPID}/status"
|
done < "/proc/${ppid:-$PPID}/status"
|
||||||
|
|
||||||
# Make sure not to do an infinite loop
|
# Make sure not to do an infinite loop
|
||||||
[ "$pppid" = "$ppid" ] && break
|
[ "$pppid" = "$ppid" ] && break
|
||||||
pppid="$ppid"
|
pppid=$ppid
|
||||||
|
|
||||||
# get name of binary
|
# get name of binary
|
||||||
read -r name < "/proc/$ppid/comm"
|
read -r name < "/proc/$ppid/comm"
|
||||||
|
|
||||||
case $name in
|
case $name in
|
||||||
*sh|"${0##*/}") ;; # skip shells
|
*sh|"${0##*/}") ;; # skip shells
|
||||||
*[Ll]ogin*|*init*) break;; # exit when the top is reached
|
*[Ll]ogin*|*init*|*systemd*) break;; # exit when the top is reached
|
||||||
*) term="$name" # anything else can be assumed to be the terminal
|
# 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
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
@@ -56,7 +59,8 @@ if [ -e /proc/$$/comm ]; 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|sway|i3|[bfo]*box|*wm*) wm="${c%%-*}"; break;;
|
*bar*) ;;
|
||||||
|
awesome|xmonad*|qtile|sway|i3|[bfo]*box|*wm*) wm=${c%%-*}; break;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
@@ -64,7 +68,7 @@ if [ -e /proc/$$/comm ]; then
|
|||||||
# loop over lines in /proc/meminfo until it reaches MemTotal,
|
# loop over lines in /proc/meminfo until it reaches MemTotal,
|
||||||
# then convert the amount (second word) from KB to MB
|
# then convert the amount (second word) from KB to MB
|
||||||
while read -r line; do
|
while read -r line; do
|
||||||
eq "$line" "MemTotal*" && set -- $line && break
|
eq "$line" 'MemTotal*' && set -- $line && break
|
||||||
done < /proc/meminfo
|
done < /proc/meminfo
|
||||||
mem="$(( $2 / 1000 ))MB"
|
mem="$(( $2 / 1000 ))MB"
|
||||||
|
|
||||||
@@ -72,7 +76,7 @@ if [ -e /proc/$$/comm ]; then
|
|||||||
while read -r line; do
|
while read -r line; do
|
||||||
case $line in
|
case $line in
|
||||||
vendor_id*) vendor="${line##*: } ";;
|
vendor_id*) vendor="${line##*: } ";;
|
||||||
model\ name*) cpu="${line##*: }"; break;;
|
model\ name*) cpu=${line##*: }; break;;
|
||||||
esac
|
esac
|
||||||
done < /proc/cpuinfo
|
done < /proc/cpuinfo
|
||||||
|
|
||||||
@@ -85,21 +89,30 @@ if [ -e /proc/$$/comm ]; then
|
|||||||
|
|
||||||
## Kernel
|
## Kernel
|
||||||
read -r _ _ version _ < /proc/version
|
read -r _ _ version _ < /proc/version
|
||||||
kernel="${version%%-*}"
|
kernel=${version%%-*}
|
||||||
eq "$version" "*Microsoft*" && ID="fake $ID"
|
eq "$version" '*Microsoft*' && ID="fake $ID"
|
||||||
|
|
||||||
## Motherboard // laptop
|
## Motherboard // laptop
|
||||||
read -r model < /sys/devices/virtual/dmi/id/product_name
|
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
|
||||||
|
|
||||||
## Packages
|
## Packages
|
||||||
# clean environment, then make every file in the dir an argument,
|
# clean environment, then make every file in the dir an argument,
|
||||||
# then save the argument count to $pkgs
|
# then save the argument count to $pkgs
|
||||||
set --
|
set --
|
||||||
[ -d /var/db/kiss/installed ] && set -- /var/db/kiss/installed/*
|
# kiss, arch, debian, void, gentoo
|
||||||
[ -d /var/lib/pacman/local ] && set -- /var/lib/pacman/local/[0-9a-z]*
|
for i in '/var/db/kiss/installed/*' '/var/lib/pacman/local/[0-9a-z]*' \
|
||||||
[ -d /var/lib/dpkg/info ] && set -- /var/lib/dpkg/info/*.list
|
'/var/lib/dpkg/info/*.list' '/var/db/xbps/.*' '/var/db/pkg/*/*'; do
|
||||||
[ -d /var/db/xbps ] && set -- /var/db/xbps/.*
|
set -- $i
|
||||||
[ -d /var/db/pkg ] && set -- /var/db/pkg/*/* # gentoo
|
[ $# -gt 1 ] && break
|
||||||
|
done
|
||||||
pkgs=${###0}
|
pkgs=${###0}
|
||||||
|
|
||||||
read -r host < /proc/sys/kernel/hostname
|
read -r host < /proc/sys/kernel/hostname
|
||||||
@@ -111,7 +124,7 @@ elif [ -f /var/run/dmesg.boot ]; then
|
|||||||
## OpenBSD cpu/mem/name
|
## OpenBSD cpu/mem/name
|
||||||
while read -r line; do
|
while read -r line; do
|
||||||
case $line in
|
case $line in
|
||||||
"real mem"*)
|
'real mem'*)
|
||||||
# use the pre-formatted value which is in brackets
|
# use the pre-formatted value which is in brackets
|
||||||
mem=${line##*\(}
|
mem=${line##*\(}
|
||||||
mem=${mem%\)*}
|
mem=${mem%\)*}
|
||||||
@@ -152,7 +165,7 @@ elif [ -f /var/run/dmesg.boot ]; then
|
|||||||
FreeBSD*)
|
FreeBSD*)
|
||||||
# If the OS is already set, no need to set it again
|
# If the OS is already set, no need to set it again
|
||||||
[ "$ID" ] && continue
|
[ "$ID" ] && continue
|
||||||
ID="${line%%-R*}"
|
ID=${line%%-R*}
|
||||||
;;
|
;;
|
||||||
|
|
||||||
CPU:*)
|
CPU:*)
|
||||||
@@ -166,7 +179,7 @@ elif [ -f /var/run/dmesg.boot ]; then
|
|||||||
vendor="${vendor%%\"*} "
|
vendor="${vendor%%\"*} "
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"real memory"*)
|
'real memory'*)
|
||||||
# Get the pre-formatted amount which is inside brackets
|
# Get the pre-formatted amount which is inside brackets
|
||||||
mem=${line##*\(}
|
mem=${line##*\(}
|
||||||
mem=${mem%\)*}
|
mem=${mem%\)*}
|
||||||
@@ -200,27 +213,27 @@ elif v=/System/Library/CoreServices/SystemVersion.plist; [ -f "$v" ]; then
|
|||||||
done < "$v"
|
done < "$v"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
eq "$0" "*fetish" && printf 'Step on me daddy\n' && exit
|
eq "$0" '*fetish' && printf 'Step on me daddy\n' && exit
|
||||||
|
|
||||||
# help i dont know if it's a capital consistently
|
# help i dont know if it's a capital consistently
|
||||||
eq "$wm" "*[Gg][Nn][Oo][Mm][Ee]*" && wm="foot DE"
|
eq "$wm" '*[Gg][Nn][Oo][Mm][Ee]*' && wm='foot DE'
|
||||||
|
|
||||||
## GTK
|
## GTK
|
||||||
while read -r line; do
|
while read -r line; do
|
||||||
eq "$line" "gtk-theme*" && gtk="${line##*=}" && break
|
eq "$line" 'gtk-theme*' && gtk=${line##*=} && break
|
||||||
done < "${XDG_CONFIG_HOME:=$HOME/.config}/gtk-3.0/settings.ini"
|
done < "${XDG_CONFIG_HOME:=$HOME/.config}/gtk-3.0/settings.ini"
|
||||||
|
|
||||||
# Shorten $cpu and $vendor
|
# Shorten $cpu and $vendor
|
||||||
# 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
|
||||||
vendor="${vendor##*Authentic}"
|
vendor=${vendor##*Authentic}
|
||||||
vendor="${vendor##*Genuine}"
|
vendor=${vendor##*Genuine}
|
||||||
cpu="${cpu##*) }"
|
cpu=${cpu##*) }
|
||||||
cpu="${cpu%% @*}"
|
cpu=${cpu%% @*}
|
||||||
cpu="${cpu%% CPU}"
|
cpu=${cpu%% CPU}
|
||||||
cpu="${cpu##CPU }"
|
cpu=${cpu##CPU }
|
||||||
cpu="${cpu##*AMD }"
|
cpu=${cpu##*AMD }
|
||||||
cpu="${cpu%% with*}"
|
cpu=${cpu%% with*}
|
||||||
cpu="${cpu% *-Core*}"
|
cpu=${cpu% *-Core*}
|
||||||
|
|
||||||
col() {
|
col() {
|
||||||
printf ' '
|
printf ' '
|
||||||
|
|||||||
Reference in new issue
Block a user