Files
dotfile/home/.local/bin/fetch
T
2023-05-25 01:18:06 +05:45

181 lines
6.7 KiB
Bash
Executable File

#!/bin/bash
c=3 b=4
for j in c b; do
for i in {0..7}; do
printf -v $j$i "%b" "\e[${!j}${i}m"
done
done
user=$(whoami)
host=$(uname -a | awk '{print $2}')
memory=$(free -h)
os=$(source /etc/os-release && echo $PRETTY_NAME)
kernel=$(uname -sr)
wm="$(xprop -id $(xprop -root -notype | awk '$1=="_NET_SUPPORTING_WM_CHECK:"{print $5}') -notype -f _NET_WM_NAME 8t | grep "WM_NAME" | cut -f2 -d \")"
mem=$(free -m | sed -n 's/^Mem:\s\+[0-9]\+\s\+\([0-9]\+\)\s.\+/\1/p')
pkgs="$(pacman -Q | wc -l)"
shell=$(echo "$SHELL" | awk -F/ '{for ( i=1; i <= NF; i++) sub(".", substr(toupper($i),1,1) , $i); print $NF}')
colors=$(for i in {0..7}; do echo -en "\e[${1}$((30 + $i))m  "; done)
license="GNU-GPL3"
get_mem(){
while IFS=":" read -r a b; do
case $a in
"MemTotal") ((mem_used+=${b/kB})); mem_total="${b/kB}" ;;
"Shmem") ((mem_used+=${b/kB})) ;;
"MemFree" | "Buffers" | "Cached" | "SReclaimable")
mem_used="$((mem_used-=${b/kB}))"
;;
esac
done < /proc/meminfo
mem_used="$((mem_used / 1024))"
mem_total="$((mem_total / 1024))"
}
get_mem
get_uptime() {
# Uptime works by retrieving the data in total seconds and then
# converting that data into days, hours and minutes using simple
# math.
IFS=. read -r s _ </proc/uptime
# Convert the uptime from seconds into days, hours and minutes.
d=$((s / 60 / 60 / 24))
h=$((s / 60 / 60 % 24))
m=$((s / 60 % 60))
# Only append days, hours and minutes if they're non-zero.
case "$d" in [!0]*) uptime="${uptime}${d}d " ;; esac
case "$h" in [!0]*) uptime="${uptime}${h}h " ;; esac
case "$m" in [!0]*) uptime="${uptime}${m}m " ;; esac
echo ${uptime:-0m}
}
get_gpu(){
# Read GPUs into array.
gpu_cmd="$(lspci -mm | awk -F '\"|\" \"|\\(' \
'/"Display|"3D|"VGA/ {a[$0] = $1 " " $3 " " $4}
END {for(i in a) {if(!seen[a[i]]++) print a[i]}}')"
IFS=$'\n' read -d "" -ra gpus <<< "$gpu_cmd"
# Remove duplicate Intel Graphics outputs.
# This fixes cases where the outputs are both
# Intel but not entirely identical.
#
# Checking the first two array elements should
# be safe since there won't be 2 intel outputs if
# there's a dedicated GPU in play.
[[ "${gpus[0]}" == *Intel* && "${gpus[1]}" == *Intel* ]] && unset -v "gpus[0]"
for gpu in "${gpus[@]}"; do
# GPU shorthand tests.
[[ "$gpu_type" == "dedicated" && "$gpu" == *Intel* ]] || \
[[ "$gpu_type" == "integrated" && ! "$gpu" == *Intel* ]] && \
{ unset -v gpu; continue; }
case $gpu in
*"Advanced"*)
brand="${gpu/*AMD*ATI*/AMD ATI}"
brand="${brand:-${gpu/*AMD*/AMD}}"
brand="${brand:-${gpu/*ATI*/ATi}}"
gpu="${gpu/\[AMD\/ATI\] }"
gpu="${gpu/\[AMD\] }"
gpu="${gpu/OEM }"
gpu="${gpu/Advanced Micro Devices, Inc.}"
gpu="${gpu/*\[}"
gpu="${gpu/\]*}"
gpu="$brand $gpu"
;;
*"NVIDIA"*)
gpu="${gpu/*\[}"
gpu="${gpu/\]*}"
gpu="$gpu"
;;
*"MCST"*)
gpu="${gpu/*MCST*MGA2*/MCST MGA2}"
;;
*"VirtualBox"*)
gpu="VirtualBox Graphics Adapter"
;;
*) continue ;;
esac
if [[ "$gpu_brand" == "off" ]]; then
gpu="${gpu/AMD }"
gpu="${gpu/NVIDIA }"
gpu="${gpu/Intel }"
fi
echo "${subtitle:+${subtitle}${gpu_name}}" "$gpu"
done
}
get_cpu() {
# Get CPU name.
cpu_file="/proc/cpuinfo"
case $kernel_machine in
"frv" | "hppa" | "m68k" | "openrisc" | "or"* | "powerpc" | "ppc"* | "sparc"*)
cpu="$(awk -F':' '/^cpu\t|^CPU/ {printf $2; exit}' "$cpu_file")"
;;
"s390"*)
cpu="$(awk -F'=' '/machine/ {print $4; exit}' "$cpu_file")"
;;
"ia64" | "m32r")
cpu="$(awk -F':' '/model/ {print $2; exit}' "$cpu_file")"
[[ -z "$cpu" ]] && cpu="$(awk -F':' '/family/ {printf $2; exit}' "$cpu_file")"
;;
*)
cpu="$(awk -F '\\s*: | @' \
'/model name|Hardware|Processor|^cpu model|chip type|^cpu type/ {
cpu=$2; if ($1 == "Hardware") exit } END { print cpu }' "$cpu_file")"
;;
esac
echo $cpu
}
init() {
init=$(readlink /sbin/init)
init=${init##*/}
init=${init%%-*}
export init
}
init
cat <<EOF
${c5} ┏━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┓
${c5} ┃  Systen Fetch ┃ ${c2} ${c0} ${c3} ${c0}${c1}  ${c5} ┃  ${c2}$user${c5}@${c2}$host
${c5} ┣━━━━━━━━━━━━━━━━━┻━━━━━━━━━━┫
${c5} ┃ ┃ ${c5} ${c4}OS ${c5}- ${c4} $os
${c5} ┃ ${c1} ) ) ${c5} ┃ ${c5} ${c4}Kernel ${c5}- ${c4} $kernel
${c5} ┃ ${c1} ( ( ${c5} ┃ ${c5}缾 ${c4}WM ${c5}- ${c4} $wm
${c5} ┃ ${c2} ........ ${c5} ┃ ${c5} ${c4}Shell ${c5}- ${c4} $shell
${c5} ┃ ${c2} | |] ${c5} ┃ ${c5}碌 ${c4}Init ${c5}- ${c4} $init
${c5} ┃ ${c2} \ / ${c5} ┃ ${c5} ${c4}pkgs ${c5}- ${c4} $pkgs
${c5} ┃ ${c2} '____' ${c5} ┃ ${c5} ${c4}uptime ${c5}- ${c4} $(get_uptime)
${c5} ┃ ┃ ${c5} ${c4}CPU ${c5}- ${c4} $(get_cpu)
${c5} ┃  ${c4} Developed by :${c2} 00xjack ${c5} ┃ ${c5}󰢮 ${c4}GPU ${c5}- ${c4}$(get_gpu)
${c5} ┃  ${c2} GitHub : S4NKALP ${c5} ┃ ${c5} ${c4}memory ${c5}- ${c4} $mem_used $(echo / ) $mem_total
${c5} ┃ ${c1} ${c5} ┃
${c5} ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ${c0}  ${c1}  ${c2}  ${c3}  ${c4} 󰮯 ${c5}  ${c6}  ${c7} 
EOF
# ${c5} ${c4} $(echo LICENSE) ${c5}- ${c4} $license