2021-07-16 00:28:37 +02:00
# Fancy waifu motd
2021-09-21 23:09:03 +02:00
MOTDPATH = " $( cd -- " $( dirname " $0 " ) " >/dev/null 2>& 1 ; pwd -P ) " # path to motd folder
2021-07-24 12:02:25 +02:00
CACHEFILE = "/tmp/waifu.cache" # to cache waifu state
2021-07-16 03:25:59 +02:00
RESOLUTION = 256 # resolution of waifu
2021-07-16 02:55:53 +02:00
CENTER = true # center motd?
2021-07-29 22:08:09 +02:00
LOLCAT = false # use lolcat? (start delay)
2021-07-16 02:55:53 +02:00
UNAMEARG = "-sr" # uname arguments
UPTIMEARG = "--pretty" # uptime arguments
2021-07-16 03:25:59 +02:00
tput_cols = $( /usr/bin/tput cols) # terminal columns
MINTERMWIDTH = 200 # minimal width of term, to display motd
2021-11-15 11:00:18 +01:00
UNAMECOLOR = "\033[1;38;5;93m"
UPTIMECOLOR = "\033[1;38;5;99m"
2021-07-16 03:25:59 +02:00
WAIFUS = $(( $( ls $MOTDPATH /waifus/*.256.png | wc -w) - 1 )) # count of waifus
2021-07-16 02:55:53 +02:00
2021-07-24 12:55:40 +02:00
function output( ) {
2021-07-16 02:55:53 +02:00
val = 0
if [ $1 = = "true" ] ; then val = $(( $val + 1 )) ; fi
if [ $2 = = "true" ] ; then val = $(( $val + 2 )) ; fi
if [ -f "/usr/games/lolcat" ] ; then lx = "/usr/games/lolcat" ; else lx = "/usr/bin/lolcat" ; fi
case " $val " in
0)
2021-09-21 23:09:03 +02:00
/bin/cat $MOTDPATH /motd
uname $UNAMEARG
2021-07-16 02:55:53 +02:00
uptime $UPTIMEARG
; ;
1)
2021-07-30 18:07:27 +02:00
/bin/cat $MOTDPATH /motd | $lx
2021-11-15 11:00:18 +01:00
echo "test"
echo -en $UNAMECOLOR
2021-07-16 02:55:53 +02:00
uname $UNAMEARG | $lx
2021-11-15 11:00:18 +01:00
echo -en $UPTIMECOLOR
2021-07-16 02:55:53 +02:00
uptime $UPTIMEARG | $lx
; ;
2)
2021-07-30 18:07:27 +02:00
/bin/cat $MOTDPATH /motd | awk '{ z = ' $tput_cols ' - length; y = int(z / 2); x = z - y; printf "%*s%s%*s\n", x, "", $0, y, ""; }'
2021-11-15 11:00:18 +01:00
echo -en $UNAMECOLOR
2021-07-16 03:25:59 +02:00
uname $UNAMEARG | awk '{ z = ' $tput_cols ' - length; y = int(z / 2); x = z - y; printf "%*s%s%*s\n", x, "", $0, y, ""; }'
2021-11-15 11:00:18 +01:00
echo -en $UPTIMECOLOR
2021-07-16 03:25:59 +02:00
uptime $UPTIMEARG | awk '{ z = ' $tput_cols ' - length; y = int(z / 2); x = z - y; printf "%*s%s%*s\n", x, "", $0, y, ""; }'
2021-07-16 02:55:53 +02:00
; ;
3)
2021-07-24 12:01:00 +02:00
/bin/cat $MOTDPATH /motd | awk '{ z = ' $tput_cols ' - length; y = int(z / 2); x = z - y; printf "%*s%s%*s\n", x, "", $0, y, ""; }' | $lx
2021-11-15 11:00:18 +01:00
echo -en $UNAMECOLOR
2021-07-16 03:25:59 +02:00
uname $UNAMEARG | awk '{ z = ' $tput_cols ' - length; y = int(z / 2); x = z - y; printf "%*s%s%*s\n", x, "", $0, y, ""; }' | $lx
2021-11-15 11:00:18 +01:00
echo -en $UPTIMECOLOR
2021-07-16 03:25:59 +02:00
uptime $UPTIMEARG | awk '{ z = ' $tput_cols ' - length; y = int(z / 2); x = z - y; printf "%*s%s%*s\n", x, "", $0, y, ""; }' | $lx
2021-07-16 02:55:53 +02:00
; ;
esac
2021-11-15 11:00:18 +01:00
printf '\033[0m' #reset colors
}
2021-07-16 00:28:37 +02:00
2021-07-29 22:08:09 +02:00
# if [ $tput_cols -gt $MINTERMWIDTH ]
# then
2021-07-16 00:28:37 +02:00
if [ $TERM = = "xterm-kitty" ]
then
if [ $(( 0 + RANDOM % 2 )) -eq 0 ]
then
if [ -f " $CACHEFILE " ]
then
WAIFU = $( /bin/cat $CACHEFILE )
else
touch $CACHEFILE
echo 0 > $CACHEFILE
WAIFU = $(( 0 + RANDOM % $WAIFUS ))
fi
if [ $WAIFU -gt $WAIFUS ]
then
echo 0 > $CACHEFILE
WAIFU = $(( 0 + RANDOM % $WAIFUS ))
else
2021-07-16 02:55:53 +02:00
echo $(( $WAIFU + 1 )) > $CACHEFILE
2021-07-16 00:28:37 +02:00
fi
2021-07-16 03:25:59 +02:00
if $CENTER ; then kitty +kitten icat " $MOTDPATH /waifus/waifu- $WAIFU . $RESOLUTION .png " ; else kitty +kitten icat --align left " $MOTDPATH /waifus/waifu- $WAIFU . $RESOLUTION .png " ; fi
2021-07-16 00:28:37 +02:00
else
2021-07-16 03:25:59 +02:00
if $CENTER ; then kitty +kitten icat " $MOTDPATH /waifus/waifu- $(( 0 + RANDOM % $WAIFUS )) . $RESOLUTION .png " ; else kitty +kitten icat --align left " $MOTDPATH /waifus/waifu- $(( 0 + RANDOM % $WAIFUS )) . $RESOLUTION .png " ; fi
2021-07-16 00:28:37 +02:00
fi
fi
2021-07-16 02:55:53 +02:00
output $LOLCAT $CENTER
2021-07-29 22:08:09 +02:00
# fi