Skip to content

Instantly share code, notes, and snippets.

@4np
Last active June 5, 2018 06:35
Show Gist options
  • Save 4np/5421296 to your computer and use it in GitHub Desktop.
Save 4np/5421296 to your computer and use it in GitHub Desktop.
Calculate the number of seconds until weekend :) Works especially well together with Geektools and bash geeklet that runs every second... Shows a party hat (πŸŽ‰) when it's weekend :)
#!/bin/sh
NOW=`date +"%s"`
NEXT_FRIDAY=`date -v+fri +"%m%d"`
FRIDAY_5PM=`date -j $NEXT_FRIDAY"1700" +"%s"`
SECONDS_LEFT=$[$FRIDAY_5PM - $NOW]
DAY_OF_THE_WEEK=`date +"%u"`
# is it weekend yet?
if [[ ( $SECONDS_LEFT -lt 0 || $DAY_OF_THE_WEEK > 5 ) ]]; then
# yes! It's weekend
if [ $SECONDS_LEFT -gt -2 && $SECONDS_LEFT -lt 0 ]; then
# weekend just started, say it!
say "Oh yeah! It is weekend!"
fi
echo "πŸŽ‰πŸ»πŸΈ"
else
# output the number of seconds until it's weekend
echo "⏰ $SECONDS_LEFT"
fi
@4np
Copy link
Author

4np commented Apr 19, 2013

countdown
counting down to Friday 17:00...

weekend
it's weekend!

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