From 71c3ca3721d0f3e6f88b2069166a3027b5a8aabe Mon Sep 17 00:00:00 2001 From: Yigid BALABAN Date: Sun, 8 Sep 2024 22:47:04 +0300 Subject: [PATCH] OK! here's the best fetcher ever, and it's in Bash --- fetch.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 fetch.sh diff --git a/fetch.sh b/fetch.sh new file mode 100755 index 0000000..01420bd --- /dev/null +++ b/fetch.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# +# yigid balaban +# fetchsh, fetch script alternative to neofetch +# revision 1 + +f_mem_read() { + local result="error reading memory" + result=$(grep "$1" /proc/meminfo | sed "s/$1://g" | sed "s/kB//g" | xargs) + echo "$result" +} + +f_mem_format() { + result=$(echo "$1" | awk '{$1/=1048576;printf "%.2fGiB\n",$1}') + echo "$result" +} + +f_color() { + for token in "$@"; do + tokens+=("\u001b[31m$token\u001b[0m") + done + + echo -e "Hi ${tokens[0]}, welcome to ${tokens[1]}. I see that you're on ${tokens[2]}," + echo -e "running with Linux ${tokens[3]}. You've ${tokens[4]} packages installed." + echo -e "Your RAM usage is ${tokens[5]} / ${tokens[6]} and uptime is ${tokens[7]}." +} + +raw_memt=$(f_mem_read 'MemTotal') +raw_mema=$(f_mem_read 'MemAvailable') + +name=$(whoami) +hostname=$(uname -n) +distname='Arch GNU+Linux' +kernvers=$(uname -r) +packgcnt=$(pacman -Q | wc -l) +memtotal=$(f_mem_format "$raw_memt") +memfree=$(f_mem_format $((raw_memt - raw_mema))) +uptime=$(uptime -p | sed 's/up//g' | xargs) + +f_color "$name" "$hostname" "$distname" "$kernvers" "$packgcnt" "$memfree" "$memtotal" "$uptime"