Skip to content

Instantly share code, notes, and snippets.

@mjf
Created November 14, 2011 22:52
Show Gist options
  • Save mjf/1365484 to your computer and use it in GitHub Desktop.
Save mjf/1365484 to your computer and use it in GitHub Desktop.
XTerm (256-colours) "pulsing" date in the top right corner of the terminal
#! /bin/sh
# Pulsing date XTerm mastery
# Copyright (C) 2011 Matous J. Fialka, <http://mjf.cz/>
# Released under the terms of The MIT License
# Prerequisities: flock tput TERM=xterm-256color
lock()
{
while ! flock -w 1 1 2>/dev/null
do
:
done
}
unlock()
{
while ! flock -w 1 -u 1 2>/dev/null
do
:
done
}
trap unlock SIGHUP SIGINT SIGQUIT SIGTERM
while :
do
for C in 17 18 19 20 21 21 20 19 18 17 # this seq. may vary
do
D=`date +%T`
X=$((`tput cols`-9))
lock
echo -n -e "\e7\e[0;${X}H\e[37;0m\e[48;5;${C}m $D \e8\e[0m"
unlock
sleep 0.1
done
done &
@mjf
Copy link
Author

mjf commented Nov 14, 2011

This is just little hack for fun and to show one of my friends how to lock standard output in order to do such silly things. Try it like this:

$ pulsingdate.sh
$ top -d 0.1

Note that the colour seq. may vary from environment to environment. Just choose values you like... Enjoy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment