misc-scripts/avalifetch

79 lines
2.5 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/sh
set -euf
COLORS="178 245 36 163 239 15"
ASCIIART="$XDG_CONFIG_HOME/neofetch/avali"
GAP=2
system_info() {
# use the function "iprint" for everything
# use $(col x) to get an arbitrary 0-255 color
# use $(bold) to bold, $(res) to reset formatting
iprint "$(col 10)$(bold)${USER}$(res)$(col 15)@$(bold)$(col 10)$(uname -n)"
iprint "$(col 7)$(bold)--------------"
iprint "$(col 15)$(bold)OS:$(res)$(col 10) Void Linux"
iprint "$(col 15)$(bold)Kernel:$(res)$(col 11) $(uname -r)"
iprint "$(col 15)$(bold)Shell:$(res)$(col 13) ${SHELL##*/}"
iprint "$(col 15)$(bold)WM:$(res)$(col 7) awesome"
iprint "$(col 15)$(bold)Terminal:$(res)$(col 7) urxvt"
# iprint "$(col 15)$(bold)CPU:$(res)$(col 7) $(cat /proc/cpuinfo | grep -i '^model name' | sort -u | sed -r 's/^model name\t: (.+)/\1/')"
iprint "$(col 15)$(bold)Packages:$(res)$(col 7) $(xbps-query -l | rg -c .)"
iprint "$(col 15)$(bold)Uptime:$(res)$(col 7) $(uptime -p | cut -d ' ' -f 2-)"
iprint "$(col 15)$(bold)Song:$(res)$(col 7) $(mpc -f '%artist% - %title%' current)"
iprint "$(col 7)$(bold)--------------"
iprint ""
iprint "$(col 0)███$(col 1)███$(col 2)███$(col 3)███$(col 4)███$(col 5)███$(col 6)███$(col 7)███"
iprint "$(col 8)███$(col 9)███$(col 10)███$(col 11)███$(col 12)███$(col 13)███$(col 14)███$(col 15)███"
}
# <-+-+-+-+-+- CONFIGURATION ENDS -+-+-+-+-+-> #
colres='\033[m'
process_colors() {
colindex=1
for c; do
colesc="$(printf '%b\033[38;5;%sm' "$colres" "$c")"
eval "c$colindex="'$colesc'
colindex=$((colindex + 1))
done
}
process_ascii() {
# get maximum line length
maxlen="$(sed -e 's/\${c[1-6]}//g' "$ASCIIART" | wc -L)"
linecount="$(grep -c '^' "$ASCIIART")"
# actually do color replacement
final_ascii="$(sed \
-e "s/\${c1}/$c1/g" \
-e "s/\${c2}/$c2/g" \
-e "s/\${c3}/$c3/g" \
-e "s/\${c4}/$c4/g" \
-e "s/\${c5}/$c5/g" \
-e "s/\${c6}/$c6/g" \
"$ASCIIART")"
info_padding=$((GAP+maxlen))
}
col() { printf "\033[38;5;%sm" "$1"; }
bold() { printf '\033[1m'; }
res() { printf '\033[0m'; }
# reset formatting, move to padding, print line
iprint() { printf "%b%s\n" "\033[0m\033[${info_padding}C" "$1"; }
print_all() {
printf '%s' '[?7l' # disable line wrapping
printf '%s\n' "$final_ascii"
printf '\0337 \033[?25l' # save cursor pos & hide it
printf "\033[%sF" "$linecount" #
system_info
printf '%s' '[?7h' # enable line wrapping
printf '\0338\n\033[?25h' # restore cursor pos & unhide it
}
process_colors $COLORS
process_ascii
print_all