ArchLabs Terminal Info Script

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 :slight_smile: 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"

# directory where the smaller 200x200 cropped image will be stored
# this will be created if it doesn't exist, eg. "~/.config/al-info"

# $FG resets colors

# 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
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"
            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##*/}"
        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

# print everything out
cat <<- EOF

${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}



# draw image if $IMG and $THUMBD are set

Edit: I added some more commenting to the script for those looking to hack/customize

Lemme know what you think



\o/ i’ll try!

1 Like

Loving this man.

1 Like

Thanky you nate! Really nice idea. I just change the arrows.


Very nice, glad people like it.

@subjunkie Feel free to change all you like and share screens I love terminal eye candy :smiley:

This line here: ${OFFSET}$FG5$(rep_char $((${#USER} + 9 + ${#HOSTN})) "-")>
just uses the little rep_char function further up which repeats the character given, in this case a dash β€œ-”. Changing the "-" will change the characters under your hostname, the rest is just basic math to keep the line consistent with how long your user@hostname is.

You could also just change it to be hardcoded, as a user theres no need to make it work for everyone else, so long as it works for you :stuck_out_tongue:


Thank you for the tip. Now i understand a liitle bit more, how those things working.


Also, I’ll edit my original post but I should have mentioned

# full path the image you want displayed eg. "~/Pictures/image.png"

# directory where the smaller 200x200 cropped image will be stored
# this will be created if it doesn't exist, eg. "~/.config/al-info"

With urxvt images are displayed properly without issue in my testing, other terminals are hit and miss, some work, some not so great and the image disappears.


Apologies for the lame question, but where can I find the script so I can mess about with it?

@philT, al-info is in /bin


Cheers mate. Got it!

Actually, while Im here…

Is there a simple way just to show the info and remove the ascii art from the terminal?

Looks cool, but I just want to simplify the output.

I put it in the following way @philT . Simple and with an image. In the same way as @natemaia .

# print everything out
cat <<- EOF

${OFFSET}$FG6->$FG2 Terminal$FG1:             $FG1$(sed 's/-256color//g' <<< "$TERM")
${OFFSET}$FG6->$FG2 Ventanas WM$FG1:          $FG1$(cur_wm)
${OFFSET}$FG6->$FG2 Mi Shell$FG1:             $FG1$(basename "$SHELL")
${OFFSET}$FG6->$FG2 Paquetes totales$FG1:     $FG1$(pacman -Qq | wc -l)
${OFFSET}$FG6->$FG2 Kernel de linux$FG1:      $FG1$(uname -r | cut -d "-" -f1)
${OFFSET}$FG6->$FG2 Distro$FG1:               $FG1${DIST}
${OFFSET}$FG6->$FG2 En marcha desde hace$FG1: $FG1${UPT}


${OFFSET}$FG3$(rep_char $((${#USER} + 20 + ${#HOSTN})) "_")#!
${OFFSET}$FG3$(rep_char $((${#USER} + 25 + ${#HOSTN})) "_")#!


Thanks very much! @Negata

1 Like