Hello all,
A simple little system info script to share, it can display images if you have w3m
and a terminal that supports it. A version without the image display, but with our distro ascii art has been included in our pipemenus package, try it out
al-info
Back on subject
#!/usr/bin/env bash
# extremely simple system info script
# written by Nathaniel Maia, 2017-2018
# set these to try image display
# full path the image you want displayed eg. "~/Pictures/image.png"
IMG=""
# directory where the smaller 200x200 cropped image will be stored
# this will be created if it doesn't exist, eg. "~/.config/al-info"
THUMBD=""
# $FG resets colors
FG=$'\e[0m'
# Set colors as $FG0-7
for n in {0..7}; do printf -v FG${n} "%b" "\e[3${n}m"; done
# repeat $2 n times, where n = $1
rep_char() { nstring="$(printf "%$1s")" ; echo "${nstring// /$2}" ; }
# current window manager
cur_wm() {
[[ $DISPLAY && ! $WM ]] && {
ID="$(xprop -root -notype _NET_SUPPORTING_WM_CHECK)"
WM="$(xprop -id "${ID##* }" -notype -len 100 -f _NET_WM_NAME 8t)"
WM="${WM/*WM_NAME = }" WM="${WM/\"}" WM="${WM/\"*}"
} || WM="${WM:-tty${TTY:9}}" # fallback for tty or unsupported WM
echo "$WM"
}
# hostname, distro and uptime strings
HOSTN=$(hostname)
DIST=$(grep "^ID=" /etc/os-release | awk -F'=' '{print tolower($2)}')
UPT=$(uptime -p | awk -NF'up ' '{print $2}' | sed 's/ minutes\?/m/;s/ hours\?/h/;s/ days\?/d/')
# larger offset when using image display
[[ $IMG ]] && OFFSET="$(rep_char 38 ' ')" || OFFSET=" "
image() {
# only display images when IMG is set and xorg is running
# the tty console doesnt have the ability to
if [[ $DISPLAY && $IMG && -e $IMG ]]; then
# we dont need to crop and resize the image if it already exists
if [[ $THUMBD && ! -e $THUMBD/${IMG##*/} ]]; then
[[ ! -d $THUMBD ]] && mkdir -p $THUMBD # create the folder if needed
# get the original image size for cropping
if [[ -z "$S" ]]; then
S="$(identify -format "%w %h" "$IMG")"
w="${S%% *}" h="${S##* }"
((h > w)) && S="$w" || S="$h"
fi
c="$(convert "$IMG" -colorspace srgb -format "%[pixel:p{0,0}]" info:)"
# crop if needed and scale to 200x200 placing it in $THUMBD
convert -background none "$IMG" -trim +repage -gravity south -background "$c" \
-extent "$S"x"$S" -scale 200x200 "$THUMBD/${IMG##*/}"
fi
sleep 0.05
# display the image using w3mimgdisplay
# 1 pixel offsets from edge and 200x200 image size
printf "%b\n" "0;1;1;1;200;200;;;;;"$THUMBD/${IMG##*/}"\n4;\n3;" | \
/usr/lib/w3m/w3mimgdisplay -bg none &>/dev/null
fi
}
clear
# print everything out
cat <<- EOF
${OFFSET}$FG5--->$FG $FG4$USER$FG2@$FG6$HOSTN
${OFFSET}$FG5$(rep_char $((${#USER} + 9 + ${#HOSTN})) "-")>
${OFFSET}$FG6->$FG terminal$FG1: $FG4$(sed 's/-256color//g' <<< "$TERM")
${OFFSET}$FG6->$FG current wm$FG1: $FG4$(cur_wm)
${OFFSET}$FG6->$FG login shell$FG1: $FG4$(basename "$SHELL")
${OFFSET}$FG6->$FG total pkgs$FG1: $FG4$(pacman -Qq | wc -l)
${OFFSET}$FG6->$FG linux kernel$FG1: $FG4$(uname -r | cut -d "-" -f1)
${OFFSET}$FG6->$FG distribution$FG1: $FG4${DIST}
${OFFSET}$FG6->$FG total uptime$FG1: $FG4${UPT}
${OFFSET}$FG1ββββ$FG2ββββ$FG3ββββ$FG4ββββ$FG5ββββ$FG6ββββ$FG7ββββ$FG
EOF
# draw image if $IMG and $THUMBD are set
image
Edit: I added some more commenting to the script for those looking to hack/customize
Lemme know what you think
Cheers