16 Commits
Author SHA1 Message Date
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
3 changed files with 88 additions and 65 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
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
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:
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
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.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+15 -3
View File
@@ -1,8 +1,20 @@
<h2 align="center">fet.sh</h1>
<div align="center">
<h1>fet.sh</h1>
fetch written in POSIX shell with no external commands
<br>
<img src="screenshot.png" width="250px">
</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`
+62 -45
View File
@@ -1,36 +1,44 @@
#!/bin/sh
#
# this is my attempt at trying to make a fetch using only posix shell
# without any external commands
# fet.sh
# a fetch in pure POSIX shell
#
# supress errors
exec 2>/dev/null
set --
_() { # [ a = b ] with globbing
! case $1 in # default return is 0 so double negative saves a line
$2) return 1
esac
}
## Terminal
while [ ! "$term" ]; do
while IFS=': ' read -r key val; do
case $key in
PPid) ppid=$val; break;;
esac
# 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
_ "$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##*/}") ;;
*[Ll]ogin*|*init*) term=linux;;
*) term="$name";;
*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
if [ "$XDG_CURRENT_DESKTOP" ]; then
wm="$XDG_CURRENT_DESKTOP"
elif [ "$DESKTOP_SESSION" ]; then
wm="$DESKTOP_SESSION"
elif [ "$DISPLAY" ]; then
# non-standard WMs
# loop over all processes and check the binary name
for i in /proc/*/comm; do
read -r c < "$i"
case $c in
@@ -40,16 +48,15 @@ elif [ "$DISPLAY" ]; then
fi
## Distro
. /etc/os-release # lol EZ
. /etc/os-release # a common file that has variables about the distro
## 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
case $line in
MemTotal*) mem="${line##*: }"; break;;
esac
_ "$line" "MemTotal*" && set -- $line && break
done < /proc/meminfo
mem="${mem##* }"
mem="$(( ${mem%% *} / 1000 ))"
mem="$(( $2 / 1000 ))MB"
## Processor
while read -r line; do
@@ -60,7 +67,7 @@ while read -r line; do
done < /proc/cpuinfo
vendor="${vendor##*Authentic}"
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}"
@@ -79,49 +86,59 @@ up=$(printf %02d:%02d $((uptime / 60 / 60 % 24)) $((uptime / 60 % 60)))
## Kernel
read -r _ _ version _ < /proc/version
kernel="${version%%-*}"
case $version in
*Microsoft*) [ "$ID" ] && ID="fake $ID";;
esac
_ "$version" "*Microsoft*" && ID="fake $ID"
## GTK
while read -r line; do
case $line in
gtk-theme*) gtk="${line##*=}"; break;;
esac
_ "$line" "gtk-theme*" && gtk="${line##*=}" && break
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/*
# 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/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=$#
print() {
[ "$2" ] && printf '\033[34m%6s\033[0m ~ %s\n' "$1" "$2"
col() {
printf ' '
for i in 1 2 3 4 5 6; do
printf '\033[9%sm▅▅' "$i"
done
printf '\033[0m\n'
}
print() {
[ "$2" ] && printf '\033[9%sm%6s\033[0m%b%s\n' \
"${accent:-4}" "$1" "${separator:- ~ }" "$2"
}
echo
read -r host < /etc/hostname
printf '%7s@%s\n' "$USER" "$host"
read -r host < /proc/sys/kernel/hostname
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"
# default value
: "${info:=n user os sh wm up gtk cpu mem host kern pkgs term col n}"
printf ' '
for i in 1 2 3 4 5 6; do
printf '\033[9%sm▅▅' "$i"
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
printf '\033[0m\n\n'