43 Commits
Author SHA1 Message Date
GaugeK 8b3af10779 Shorten CPU name and remove dir from wm 2020-08-25 04:28:07 +10:00
gk 4a7caeabe5 Merge pull request #20 from elkowar/readme_add_nix
Add nixpkgs package to readme
2020-08-25 02:12:09 +10:00
elkowar dc190ac7ac Add nixpkgs package to readme 2020-08-24 15:25:41 +02:00
GaugeK 71afae542c Fix inaccurated arch package count (Solves #19) 2020-08-24 02:46:19 +10:00
gk 33d1029e8b Merge pull request #18 from MatthiasCoppens/repology
Add Gentoo package
2020-08-22 18:43:48 +10:00
GaugeK 402217d114 don't check if DE variables exist before setting them, fix location of terminal comment 2020-08-22 15:34:37 +10:00
GaugeK 293b388623 Sane function name for [ a = b ] with globbing clone 2020-08-22 14:50:06 +10:00
Matthias Coppens 473ed6f54f Add Gentoo package
I added the Gentoo package to the README. I've already
written a report to Repology that the projects [fet.sh, fet-sh and fetsh](https://repology.org/project/fet.sh/related) should be merged.
When these are merged, you can use this Repology badge:
[![Packaging status](https://repology.org/badge/vertical-allrepos/fet.sh.svg)](https://repology.org/project/fet.sh/versions)
2020-08-21 21:33:12 +02:00
GaugeK 5dd087585c Check for os-release in /etc and /usr/lib 2020-08-22 04:58:22 +10:00
GaugeK 0ac1b7d216 Detect 'i3' as wm without any globbing 2020-08-22 04:54:12 +10:00
GaugeK b7fbb8784f Merge branch 'MatthiasCoppens-master' into master 2020-08-22 04:52:36 +10:00
GaugeK 6374278cac Fix file conflicts between '6gk:master' and 'MatthiasCoppens:master' 2020-08-22 04:48:51 +10:00
gk ce60c65e85 Merge pull request #16 from mfs/fix-xmonad
Detect xmonad.
2020-08-22 04:40:24 +10:00
gk 5b0c166444 Merge branch 'master' into fix-xmonad 2020-08-22 04:40:01 +10:00
GaugeK f139798f16 Remove faulty tmux support
Tmux's PPid is the 1, so skipping that makes the term your init
2020-08-22 04:14:55 +10:00
GaugeK c158f06c4d replace *box* with *box when detecting WM so it doesn't match
virtualbox's driver
2020-08-22 03:55:06 +10:00
GaugeK 0a43ea82f3 Don't report terminal as tmux 2020-08-22 03:37:35 +10:00
Mike Sampson 55931b3bdf Detect xmonad.
When using a user config the executable is located in the users
home directory and is called $HOME/.xmonad/xmonad-x86_64-linux
2020-08-21 19:22:17 +10:00
Matthias Coppens 8f4d1cd8da Added detection of sway 2020-08-21 10:30:28 +02:00
GaugeK e377e92ee2 Don't report terminal as tmux 2020-08-21 14:01:36 +10:00
GaugeK 1f0adf29de Clean up code of BSDs, add very basic macos support (version number) 2020-08-21 13:57:14 +10:00
GaugeK 2815feda67 Basic FreeBSD support
Working: user@host, distro name, shell, cpu, mem
2020-08-21 12:43:26 +10:00
GaugeK 16a223b6c9 Basic OpenBSD support
Working: user@host, distro name, shell, cpu, mem, pkgs
2020-08-21 11:27:03 +10:00
GaugeK 4d6732246e Update screenshot 2020-08-20 23:20:12 +10:00
GaugeK c95bed41eb Fix empty cpu still printing 2020-08-20 23:19:43 +10:00
GaugeK 579e6b54fb check existence of /etc/os-release 2020-08-20 11:19:05 +10:00
GaugeK 205831ab61 fix infinite loop in bash
obsfucation is fun
2020-08-20 06:08:11 +10:00
GaugeK 8fa8da9b28 Minor code optimizations, add comments
Use a function that acts like `[ a = b ]` using case instead of
calling case every time, which results in a lot of repeated lines
2020-08-19 16:04:38 +10:00
gk 06b87fba25 Merge pull request #13 from aosync/master
KISS packages
2020-08-19 15:57:39 +10:00
Alejandro Sior b48988f214 KISS packages 2020-08-19 07:53:16 +02:00
GaugeK 4821da4d3b fix typo 2020-08-19 07:13:45 +10:00
GaugeK 75b665e153 add field to print newline 2020-08-19 05:27:15 +10:00
GaugeK a0ee667546 Add env var to change what info is displayed 2020-08-19 05:21:48 +10:00
gk acec5ad4c5 Merge pull request #12 from tumpura/master
change where hostname is read.
2020-08-19 05:18:19 +10:00
tumpura b89c509aca change where hostname is read. 2020-08-18 22:12:34 +03:00
gk 3df3b25355 Merge pull request #11 from elkowar/fix/unphuck_readme
Clean up the README file
2020-08-19 04:07:06 +10:00
gk 9dd1b3d698 Merge pull request #10 from elkowar/feature/customize_seperator
make seperator between key and value configurable via an env variable
2020-08-19 04:00:58 +10:00
elkowar 3d615c8c91 make seperator between key and value configurable via an env variable 2020-08-18 20:00:08 +02:00
elkowar ee56d6eed3 Clean up the README file
Adds documentation regarding how to customize the output, as well as phix
the phormatting.
2020-08-18 19:48:27 +02:00
GaugeK 8c30f4a730 update package name 2020-08-18 12:33:04 +10:00
GaugeK d336d54e98 add AUR package info to readme 2020-08-18 10:30:56 +10:00
GaugeK 9ae2f4d01b move from MIT to ISC license
They're functionally the same but ISC has less redundant words
2020-08-17 15:38:18 +10:00
GaugeK 6f4f6bc22c '$accent' environment variable 2020-08-17 08:08:08 +10:00
4 changed files with 243 additions and 111 deletions

No files matched your search

+11 -17
View File
@@ -1,19 +1,13 @@
Copyright (c) 2020 Gauge Krahe Copyright 2020 Gauge Krahe
Permission is hereby granted, free of charge, to any person obtaining a copy Permission to use, copy, modify, and/or distribute this software for any
of this software and associated documentation files (the "Software"), to deal purpose with or without fee is hereby granted, provided that the above
in the Software without restriction, including without limitation the rights copyright notice and this permission notice appear in all copies.
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
copies or substantial portions of the Software. WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+17 -3
View File
@@ -1,8 +1,22 @@
<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)
**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)
**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`
+215 -91
View File
@@ -1,66 +1,212 @@
#!/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
case $1 in
# if the second argument matches the first, exit normally
$2) return
# if it doesn't match, reverse the output of `:`, which makes an error
esac;! :
}
## Terminal ## DE
while [ ! "$term" ]; do wm="$XDG_CURRENT_DESKTOP"
while IFS=': ' read -r key val; do wm="$DESKTOP_SESSION"
case $key in
PPid) ppid=$val; break;;
esac
done < "/proc/${ppid:-$PPID}/status"
read -r name < "/proc/$ppid/comm" ## Distro
case $name in # freedesktop.org/software/systemd/man/os-release.html
*sh) ;; # a common file that has variables about the distro
"${0##*/}") ;; for os in /etc/os-release /usr/lib/os-release; do
*[Ll]ogin*|*init*) term=linux;; # some POSIX shells exit when trying to source a file that doesn't exist
*) term="$name";; [ -f $os ] && . $os && break
esac
done done
## WM/DE if [ -e /proc/$$/comm ]; then
if [ "$XDG_CURRENT_DESKTOP" ]; then ## Terminal
wm="$XDG_CURRENT_DESKTOP" while [ ! "$term" ]; do
elif [ "$DESKTOP_SESSION" ]; then # loop over lines in /proc/pid/status until it reaches PPid
wm="$DESKTOP_SESSION" # then save that to a variable and exit the file
elif [ "$DISPLAY" ]; then while read -r line; do
eq "$line" "PPid*" && ppid=${line##*:?} && break
done < "/proc/${ppid:-$PPID}/status"
# get name of binary
read -r name < "/proc/$ppid/comm"
case $name in
*sh|"${0##*/}") ;; # skip shells
*[Ll]ogin*|*init*) break;; # exit when the top is reached
*) term="$name" # anything else can be assumed to be the terminal
esac
done
## WM/DE
# standard variables, mostly used for DEs
[ "$DISPLAY" ] && [ ! "$wm" ] &&
# 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
awesome|xmonad|qtile|i3*|*box*|*wm*) wm="$c"; break;; awesome|xmonad*|qtile|sway|i3|*box*|*wm*) wm="${c%%-*}"; break;;
esac esac
done done
fi
## Distro ## Memory
. /etc/os-release # lol EZ # 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"
## Memory ## Processor
while read -r line; do while read -r line; do
case $line in case $line in
MemTotal*) mem="${line##*: }"; break;; vendor_id*) vendor="${line##*: } ";;
esac
done < /proc/meminfo
mem="${mem##* }"
mem="$(( ${mem%% *} / 1000 ))"
## Processor
while read -r line; do
case $line in
vendor_id*) vendor="${line##*: }";;
model\ name*) cpu="${line##*: }"; break;; model\ name*) cpu="${line##*: }"; break;;
esac esac
done < /proc/cpuinfo 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
## 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/[0-9a-z]*
[ -d /var/db/xbps ] && set -- /var/db/xbps/.*
[ -d /var/db/pkg ] && set -- /var/db/pkg/*/* # gentoo
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
eq "$0" "*fetish" && printf 'Step on me daddy\n' && exit
## GTK
while read -r line; do
eq "$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##*Authentic}"
vendor="${vendor##*Genuine}" 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="${cpu%% CPU}"
@@ -69,59 +215,37 @@ cpu="${cpu##*AMD }"
cpu="${cpu%% with*}" cpu="${cpu%% with*}"
cpu="${cpu% *-Core*}" cpu="${cpu% *-Core*}"
## Uptime col() {
# the simple math is shamefully stolen from aosync printf ' '
IFS=. read -r uptime _ < /proc/uptime for i in 1 2 3 4 5 6; do
d=$((uptime / 60 / 60 / 24)) printf '\033[9%sm▅▅' "$i"
up=$(printf %02d:%02d $((uptime / 60 / 60 % 24)) $((uptime / 60 % 60))) done
[ "$d" -gt 0 ] && up="${d}d $up" printf '\033[0m\n'
## Kernel
read -r _ _ version _ < /proc/version
kernel="${version%%-*}"
case $version in
*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
read -r model < /sys/devices/virtual/dmi/id/product_name
## Packages
[ -d /var/lib/pacman/local ] && set -- /var/lib/pacman/local/*
[ -d /var/db/xbps ] && set -- /var/db/xbps/.*
[ -d /var/db/pkg ] && set -- /var/db/pkg/*/*
[ $# -gt 0 ] && pkgs=$#
print() {
[ "$2" ] && printf '\033[34m%6s\033[0m ~ %s\n' "$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'
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 141 KiB