Skip to content

Instantly share code, notes, and snippets.

@Bombe
Last active March 31, 2016 11:17
Show Gist options
  • Save Bombe/a0b34d05c4b76cb000513e9898998381 to your computer and use it in GitHub Desktop.
Save Bombe/a0b34d05c4b76cb000513e9898998381 to your computer and use it in GitHub Desktop.
days-left
20170414120000 Revision 2017 (for Visitors)
20160701120000 Nordlicht 2016
20160812120000 Evoke 2016
#!/bin/sh
# 3B8544DA-587F-4FA7-9AFC-CB96A2B8197B
currentTime="$(date +%s)"
currentMinTime="$((2**31-1))"
currentMinEvent=""
daysFile="${HOME}/.days"
while read time event; do
eventTime="$(date -jf %Y%m%d%H%M%S "${time}"0000 +%s 2> /dev/null)"
if [ "${eventTime}" -gt "${currentTime}" -a "${eventTime}" -lt "${currentMinTime}" ]; then
if [[ -z "${1}" || ( -n "${1}" && "${event}" =~ "${1}" ) ]]; then
currentMinTime="${eventTime}"
currentMinEvent="${event}"
fi
fi
done < "${daysFile}"
if [ -z "${currentMinEvent}" ]; then
exit
fi
daysLeft="$(((${currentMinTime} - ${currentTime})/86400))"
echo "${daysLeft} days left until ${currentMinEvent}."
@Bombe
Copy link
Author

Bombe commented Mar 30, 2016

Copy days-left.sh to somewhere in your PATH, copy .days to your $HOME, and start adding entries you need to be remembered about. Calling days-left.sh will then tell you how many days are left until the next event in your list (they are sorted in the script, no need to sort them in the file).

Tested on OS X only, GNU date might want different options.

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