Skip to content

Instantly share code, notes, and snippets.

@mrdaemon
Created December 30, 2010 05:52
Show Gist options
  • Save mrdaemon/759508 to your computer and use it in GitHub Desktop.
Save mrdaemon/759508 to your computer and use it in GitHub Desktop.
This is the script exec'ed by my .bashrc that displays a crappy ascii 'picture' and text centered on screen as a banner. It was annoying to write, is completely useless and full of bashisms, but is interesting nonetheless.
#!/bin/bash
#
# rc.logo - Crappy welcome mat for unix shells
# 2010-2011 Alexandre Gauthier <alex@lab.underwares.org>
#
# Displays usless ascii logo, information and random niceties
# on login.
#
#####################################################################
GOODTERMINAL=0
PIX=$HOME/.asciilogo
FOOTER=$HOME/.logotail
# Is the terminal known, and as a side effect,
# are we running interactively?
for i in xterm xterm-color linux screen screen-bce; do
if [ "$i" = "$TERM" ] ; then
GOODTERMINAL=1
fi
done
if [ $GOODTERMINAL -eq 1 ] ; then
# Define term dimensions
# (tput cols would have worked for width)
CTERMW=`stty size | cut -d ' ' -f 2`
CTERMH=`stty size | cut -d ' ' -f 1`
# Awk subroutine to print a file center aligned
printcenter(){
awk '{
l=length()
s=int(('$CTERMW'-l)/2)
printf "%"(s+l)"s\n",$0
}' $1
}
#### begin ####
# Validate footer's existence
if [ ! -f $FOOTER ] ; then
FOOTER=""
else
# Do not print footer if terminal is too short
if [ $CTERMH -lt 30 ] ; then
FOOTER=""
fi
fi
tput clear
# Output picture
if [ -f $PIX ] ; then
imgh=`wc -l $PIX | awk '{ print $1;}'`
# Add padding for footer/tail message
if [ -n "$FOOTER" ] ; then
# Image + Footer lenght + newline
imgh=$(((${imgh}+`wc -l $FOOTER | awk '{ print $1;}'`)+1))
fi
let tposh=($CTERMH-$imgh)/2
# prepare cursor position and attributes
tput bold
tput cup $tposh 0
printcenter $PIX
else
let tposh=($CTERM-1)/2
tput cup $posh 0
tput rev
echo "[ scene missing ]"
tput sgr0
fi
# Back to normal, print footer
if [ -n "$FOOTER" ] ; then
echo ""
tput sgr0
tput dim
TMPFILE=".$$-login"
sed -e 's/%h/'"$(hostname -f)"'/g'\
-e 's/%v/'"$(uname -sr)"'/g'\
$FOOTER >> $TMPFILE
printcenter $TMPFILE
rm -f $TMPFILE
fi
tput sgr0
tput cup $CTERMH 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment