Skip to content

Instantly share code, notes, and snippets.

@thatmaheshrs
Last active August 29, 2015 13:56
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save thatmaheshrs/8898642 to your computer and use it in GitHub Desktop.
A shell script that uses Zenity to show current date and time (read more at https://bit.ly/showDateTime).
#!/bin/bash
# COPYRIGHT: That Mahesh RS (https://sites.google.com/site/thatmaheshrs)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# ---- README ----
# install this script in /usr/local/bin
# then chmod +x this script
# then you could add a keyboard shortcut to invoke this script
WEEKDAY=`date +"%A"`
MONTH=`date +"%B"`
DAYOFMONTH=`date +"%d"`
YEAR=`date +"%Y"`
DATE=`date +"%F"`
TIME=`date +"%I:%M %p %Z"`
SHOWDATE="${MONTH} ${DAYOFMONTH}, ${YEAR}"
DATE_TIME_TO_SHOW="
<span font='22' color='blue'><tt>Day : </tt></span><span font='32' color='brown'>$WEEKDAY\n</span>
<span font='22' color='blue'><tt>Date: </tt></span><span font='32' color='darkgreen'>$SHOWDATE\n</span>
<span font='22' color='blue'><tt>Time: </tt></span><span font='32' color='green'>$TIME\n\n</span>
<span font='10' color='blue'><i>Hit 'ESC' to close this window or wait till progress bar is full.</i></span>"
PROGRESS_COUNT=0
PROGRESS_COUNT_MAX=110 # in %
PROGRESS_COUNT_INCREMENT=15 # i.e. jump up 15% at a time
while [ ${PROGRESS_COUNT} -lt ${PROGRESS_COUNT_MAX} ]
do
echo ${PROGRESS_COUNT}
sleep 1
PROGRESS_COUNT=`expr ${PROGRESS_COUNT} + ${PROGRESS_COUNT_INCREMENT}`
done | zenity --progress --auto-close --no-cancel --title="Date and Time" --text="${DATE_TIME_TO_SHOW}"
@thatmaheshrs
Copy link
Author

Read more about this script here: http://bit.ly/showDateTime.

HTH!

@thatmaheshrs
Copy link
Author

Updated the script to use Zenity's "progress" dialog. Hopefully, looks better. :)

@thatmaheshrs
Copy link
Author

Code cleanup:

  1. Updated the script to remove some cruft.
  2. Also added some vars in place of magic numbers.

HTH!

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