From a0ee667546529ce23911adc23c024c52c7d62f8a Mon Sep 17 00:00:00 2001 From: GaugeK Date: Wed, 19 Aug 2020 05:21:48 +1000 Subject: [PATCH] Add env var to change what info is displayed --- README.md | 15 +++++++-------- fet.sh | 50 +++++++++++++++++++++++++++++--------------------- 2 files changed, 36 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index d184a97..a90f40f 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,20 @@ -

fet.sh

-
+

fet.sh

fetch written in POSIX shell with no external commands
- ### Installing - **Arch:** [fet.sh-git](https://aur.archlinux.org/packages/fet.sh-git/) (AUR) - **Other Distros:** copy `fet.sh` to somewhere in $PATH +**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: -```sh -$ separator=" > " fet.sh +``` +$ info='os wm sh' fet.sh ``` Supported options are: -- `accent` +- `accent` (0-7) +- `info` - `separator` diff --git a/fet.sh b/fet.sh index f476f4f..f673250 100755 --- a/fet.sh +++ b/fet.sh @@ -99,29 +99,37 @@ read -r model < /sys/devices/virtual/dmi/id/product_name [ -d /var/db/pkg ] && set -- /var/db/pkg/*/* [ $# -gt 0 ] && pkgs=$# -print() { - [ "$2" ] && printf '\033[9%sm%6s\033[0m%b%s\n' "${accent:-4}" "$1" "${separator:- ~ }" "$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" +} + +read -r host < /proc/sys/kernel/hostname echo -read -r host < /proc/sys/kernel/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 ' ' -for i in 1 2 3 4 5 6; do - printf '\033[9%sm▅▅' "$i" +for i in ${info:-user os sh wm up gtk cpu mem host kern pkgs term col}; do + case $i in + os) print os "$ID";; + sh) print sh "${SHELL##*/}";; + wm) print wm "$wm";; + up) print up "$up";; + gtk) print gtk "${gtk# }";; + gpu) print cpu "$vendor $cpu";; + mem) print mem "${mem}MB";; + 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' +echo